Creating more than one data set with a single data step
Up to now we have created only one data set with a data step, but you can create several at the same time. You need to instruct SAS about
· Which variables are to be written to the each data set. Any of the variables in the program data vector may be written to one or both data sets.
· Which observations are to be written to each data set. An observation may be written to both data sets. If you want only one dataset to receive an observation, you will have to construct a conditional output instruction.
Example 6.1 from C&P (slightly modified):
Proc Sort data=Demog2; By ID; Proc Sort data=Employee; By EmplyID; Data Active /* All PDV variables are kept */ Inactive (keep=ID Gender State); /* Only those vars listed are kept */ Merge Demog2 Employee (In=Act Rename=(EmplyID=ID)); By ID; If ACT Then Output Active; /* Active contains those records */ Else Output Inactive; /* with info from Employee. */ Run;