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?
What will the function SUM(num1, num2,...) do in a DATA step?
What will the function SUM(num1, num2,...) do in a DATA step?
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?
What does the LENGTH statement do when creating a character column?
What does the LENGTH statement do when creating a character column?
Signup and view all the answers
What will the function LOWCASE(char1) do to a character string?
What will the function LOWCASE(char1) do to a character string?
Signup and view all the answers
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?
Signup and view all the answers
What is the result of using the MAX(num1, num2,...) function?
What is the result of using the MAX(num1, num2,...) function?
Signup and view all the answers
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?
Signup and view all the answers
Signup and view all the answers
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.
Related Documents
Description
This quiz focuses on preparing data in SAS, covering essential techniques such as reading, filtering, and formatting datasets. You will learn how to manipulate columns by including or excluding them and computing new columns using expressions. Test your knowledge on these fundamental SAS data preparation skills.