![]() |
|
|
|||||||||||||||||||||||||||||||||||
|
Objectives
SET statement
The SET statement has several uses, but the most common use is to read observations from one or more SAS data sets for further processing in the DATA step. For example:
reads all of the observations from data set OLD and copies them into data set NEW. This copy can then be manipulated or subset without changing the original data set. IF statement
The subsetting IF statement enables the user to run a procedure on a selected portion of their data. The general format of the IF statement is:
Example:
The above example would select all observations where SEX equals 1 and where ETHNICITY equals 'B';. Notice that values for character variables must be enclosed in quotes and they must match exactly. Case matters. PROC SORT statement
PROC SORT reorders the cases in a SAS data set based on the values of one or more variables. You can sort in ascending or descending order. By default PROC SORT sorts in ascending order. BY variables can be numeric or character. For example,
Sorts cases first in ascending order of GENDER and within those categories, 1 (Male) and 2 (Female), the cases are further sorted in descending order of AGE. PROC SORT is used most often for sorting a data set so that other SAS procedures can process that data set in subsets using BY statements. Data sets must also be sorted before they can be merged or updated. Example:
PROC FREQ; BY GENDER; This example first sorts the SAS data set called SURVEY in ascending order of the values of the variable GENDER, 1 for males and 2 for females. Then a frequency distribution of the variable Q1 is performed for males and females separately. Note: By default, procedures work on the most recently created dataset, unless a DATA= option specifies another dataset. Session 6 ExercisesExercise 6.1
Exercise 6.2This time we will do a separate PROC PRINT for males and females without first creating separate data sets with a subsetting IF statement as we did in Exercise A.
|
||||||||||||||||||||||||||||||||||
![]()
| © University of New Mexico -- last updated -- comments to: docs@unm.edu |