Podcast
Questions and Answers
What is the purpose of the statement 'KEEP col-name;' in a DATA step?
What is the purpose of the statement 'KEEP col-name;' in a DATA step?
- To rename a column
- To include specific columns in the output (correct)
- To drop all columns except the specified one
- To exclude specific columns from the output
What will the function SUM(num1, num2,...) do in a DATA step?
What will the function SUM(num1, num2,...) do in a DATA step?
- Calculate the median of the variables
- Ignore missing values and calculate the sum (correct)
- Count the number of nonmissing values
- Calculate the maximum value among the variables
In the expression 'new-column = expression;' what must the expression yield for a newly declared column?
In the expression 'new-column = expression;' what must the expression yield for a newly declared column?
- A value that matches the existing column type
- Any valid type; SAS will auto-define attributes (correct)
- A character string only
- A numeric value only
What does the LENGTH statement do when creating a character column?
What does the LENGTH statement do when creating a character column?
What will the function LOWCASE(char1) do to a character string?
What will the function LOWCASE(char1) do to a character string?
Which DATA step statement is used to filter rows based on a condition?
Which DATA step statement is used to filter rows based on a condition?
What is the result of using the MAX(num1, num2,...) function?
What is the result of using the MAX(num1, num2,...) function?
When creating a new numeric column, what default length does SAS assign to it?
When creating a new numeric column, what default length does SAS assign to it?
Flashcards
Creating a copy of data
Creating a copy of data
Creates a copy of an existing table called input-table
and names the new copy output-table
.
Filtering rows in the DATA step
Filtering rows in the DATA step
Filters rows in a table based on a condition specified in the WHERE
clause.
Dropping columns in the DATA step
Dropping columns in the DATA step
Specifies which columns to include in the output data set using DROP
to remove columns.
Keeping columns in the DATA step
Keeping columns in the DATA step
Signup and view all the flashcards
Computing new columns
Computing new columns
Signup and view all the flashcards
Using functions in expressions
Using functions in expressions
Signup and view all the flashcards
SUM function
SUM function
Signup and view all the flashcards
CATS function
CATS function
Signup and view all the flashcards
Study Notes
Preparing Data in SAS
-
Reading and Filtering Data:
- Create a copy of data using
DATA output-table; RUN; SET input-table;
- Filter rows using
DATA output-table; RUN; SET input-table; WHERE expression;
- Specify columns for the output dataset with
DROP
orKEEP
in theDATA
step.
- Create a copy of data using
-
Specifying Columns:
- Include or exclude columns using
DROP
andKEEP
statements. - Example:
DROP col-name <col-name>;
orKEEP col-name <col-name>;
- Include or exclude columns using
-
Formatting Columns:
- Format columns within the
DATA
step usingFORMAT
statement. - Example:
FORMAT col-name format;
- Format columns within the
-
Computing New Columns:
- Create new columns using expressions.
- Example:
new-column = expression;
in theDATA
step. - The column name to create or update is on the left. The expression for computation is on the right.
- New numeric columns are 8 characters long.
- Character columns automatically adjust length to the value assigned length. Character strings must be quoted and are case sensitive.
-
Example using functions: -Example :
LENGTH char-column $ length;
-Calculates summary stats (ignoring missing values):function(argument1, argument2, ...)
-
Functions:
- Calculates common functions like sum, mean, median, range, min, max, count (non-missing and missing).
- Character functions include changing case (upper/lower/proper) and concatenation.
- Date functions extract values (month, year, day, weekday, quarter) or create SAS dates.
Conditional Processing
-
IF-THEN:
- Execute a statement if a condition is met.
IF expression THEN statement;
-
IF-THEN-ELSE:
- Execute one statement if a condition is true and another if it's false.
IF expression THEN statement; ELSE statement;
-
IF-THEN-DO:
- Execute multiple statements if a condition is true.
IF expression THEN DO; <statements>; END;
-
Example of using
IF-THEN-ELSE
andIF-THEN-DO
.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.