Previous PageNext Page

Splitting one SAS data set into two data sets
You can split a single SAS data set into two (or more) data sets using a single data step. The example program below takes the data set patient and spits it into four data sets (male, female) by (demographics, health status):

data patient;
  input ID $3. Dob mmddyy10. Gender $1. PCS 3. MCS 3.;
  format Dob date9.;
  datalines;
A3202/18/1955M 55 53
A9811/28/1967F 63 56
C0105/01/1970M 47 39
D1112/25/1930F 39 32
;
Proc Print data=patient;
  Title "Full data set";
Data   Demo_M  (drop= PCS MCS)
	 Demo_F  (drop= PCS MCS)
	 HStat_M (keep= ID PCS MCS)
	 HStat_F (keep= ID PCS MCS);
  Set patient;
  Select (Gender);
  	 When ("F") Output Demo_F HStat_F;
	 When ("M") Output Demo_M HStat_M;
	 Otherwise;
	 End;

Proc Print data=Demo_F;
  Title "Females: Demographics";
Proc Print data=Demo_M;
  Title "Males: Demographics";
Proc Print data=HStat_F;
  Title "Females: Health Status";
Proc Print data=HStat_M;
  Title "Males: Health Status";
Run; 

Previous PageTable Of ContentsNext Page