The SET Statement and Beyond in SAS

SET {ds};

With no options specified, the SAS System sequentially reads each observation in the named data sets, one observation at a time, until there are no further observations to process.

SET {ds1 ds2 ... dsn};

If multiple data sets are listed, all observations in the first data set are read before the SAS Supervisor starts reading the second data set, etc.
Up to 50 SAS data sets can be specified in a single SET statement.

OPTIONS FOR SET STATEMENT

KEEP={var-list}
DROP={var-list}
RENAME=(oldname=newname)
FIRSTOBS # 1st observation to read
OBS # last observation to read
WHERE=(condition) # The WHERE = data set option can not be used with the POINT =, FIRSTOBS = , or OBS = data set options.
END={var} # The END = option is used to identify the last observation processed by a SET statement. It creates a variable whose value is set to 0 for overy observation except for the last observation in the last data set (end of file of the final data set). When the last observation is read, the variable value is set to 1.
NOBS # creates a variable which contains the total number of observations in the input data set(s). If multiple data sets are listed in the SET statement, the value in the NOBS = variable are the total number of observations in all the listed data sets.

CONCATENATE

SET {ds1 ds2 ... dsn};
Each data set is read sequentially from the first observation in the first named data set to the last named observation in the last data set.
If the variables have different attributes and have not been previously defined in the DATA step, the first data set that defines a variable also defines the attribute for that variable. An error condition occurs if the TYPE of a variable differs between the data sets

INTERLEAVE

SET {ds1 ds2 ... dsn};
BY {var-list};
If the data sets are sorted, they can be interleaved based on order of the sorted variable(s).

COMBINE

DATA {ds};
SET {ds1};
SET {ds2};
An observation would be read from data set dsname_1 followed by an observation from data set dsname_2, and so on until an end of file condition occurs in one of the data sets. The combination of the two data sets would form a single observation in the new data set. Where the same variables exist in both data sets, the values of the second data set would overlay the values of the first data set.

posted @ 2023-08-07 12:24  helloyuen  阅读(13)  评论(0)    收藏  举报