CSULB_STAT475_handout12

# CSULB_STAT475_handout12 - STAT 475 Chapter 13 COMBINING SAS...

This preview shows pages 1–6. Sign up to view the full content.

STAT 475 Chapter 13 COMBINING SAS DATA SETS In SAS programming, sometimes it is needed to combine observations from two or more data sets into a new data set. Four methods of combining data sets are commonly used. One-to-one reading Concatenating Interleaving Match-merging ONE-TO-ONE READING The syntax is data dataset_name ; set dataset1 ; set dataset2 ; run; The rules of one-to-one reading are as follows: The new data set contains all the variables from all the input data sets. If some variables have the same name, the values read from the last data set overwrite the earlier read values. The number of observations in the new data set is the number of observations in the smallest input data set. 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Consider data set A and data set B The following SAS program combines data sets A and B with one-to-one reading. data A; input id\$ VarA\$; cards; 1 A1 2 A2 3 A3 4 A4 ; data B; input id\$ VarB\$; cards; 1 B1 2 B2 3 B3 ; data one_to_one; set A; set B; run; proc print data=one_to_one noobs; run; The result is id VarA VarB 1 A1 B1 2 A2 B2 3 A3 B3 Example. Two data sets, one containing demographic variables and the other containing quiz scores for the same individuals, are combined one-to-one. Note that in order to 2 ID VarA 1 A1 2 A2 3 A3 4 A4 ID VarB 1 B1 2 B2 3 B3
combine the data sets correctly, the observations must be listed by ID in the same way in both data sets. data demogr; input id\$ age race\$; cards; 002 18 hisp 034 22 white 010 20 hisp 011 15 hisp 017 21 white ; data quiz; input id\$ score; cards; 002 64 034 76 010 92 011 88 ; data one_to_one; set demogr; set quiz; run; proc print noobs; run; The result is id age race score 002 18 hisp 64 034 22 white 76 010 20 hisp 92 011 15 hisp 88 CONCATENATING The syntax is data dataset_name ; set dataset1 dataset2 ; 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
run; Concatenating appends the observations from dataset2 to those from dataset1 . The following SAS program concatenates data sets A and B. data concat; set A B; run ; proc print noobs; run ; The result is id VarA VarB 1 A1 2 A2 3 A3 4 A4 1 B1 2 B2 3 B3 Example. Two data sets contain demographic variables on two different groups of individuals. The data sets may be concatenated to combine the information. Note that in order to combine the data sets correctly, the variables in both data sets must have the same names. data demogr1; input id\$ age race\$; cards; 002 18 hisp 034 22 white 010 20 hisp 011 15 hisp ; data demogr2; input id\$ age race\$; cards; 012 28 white 017 21 white 088 18 hisp 110 35 hisp ; 4
data concat; set demogr1 demogr2; run; proc print noobs; run; The result is id age race 002 18 hisp 034 22 white 010 20 hisp 011 15 hisp 012 28 white 017 21 white 088 18 hisp 110 35 hisp INTERLEAVING The syntax is data dataset_name ; set dataset1 dataset2 ; by variablename(s) ; run; Interleaving

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 17

CSULB_STAT475_handout12 - STAT 475 Chapter 13 COMBINING SAS...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online