Chapter4 - Chapter 4 SAS Chapter 4 Combining SAS Data Sets...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 4 SAS - 1 - Chapter 4 Combining SAS Data Sets Once a SAS dataset is created, the user will often want to modify it or combine it with other datasets. There are many ways that SAS data sets can be combined. This chapter illustrates combining data sets vertically by adding more cases (stacking or appending data sets) and combining data sets horizontally by adding new variables (merging data sets). 4.1 Stack Data Sets Vertically (adds new cases): 1. You can use the SET statement to combine data sets vertically. The SET statement with two or more data sets, in addition to reading and modifying the data, concatenates or stacks the data sets one on top of the other. a. This is useful when you want to combine data sets with all or most of the same variables but different observations. i. It is not necessary for the data sets being combined to have their variables in the same order, or even for them to have the same variables. ii. However, it is critical that if the same variable does appear in both data sets, it should be of the same type (either character or numeric) in both. iii. If a variable is present in one data set and not in the other, the values for that variable will be missing for all cases for the data set that did not have it. iv. The order of variables in the resulting data set will reflect the order of the first data set listed. b. In the example below, the data set BOYS has different variables, which are also in a different order, than the variables in the data set GIRLS. data boys; input name $ sex $ age height teacher $; datalines ; Tom M 12 62 Smith Bob M 13 57 Green Joe M 11 59 Green Harry M 12 53 Green William M 13 60 Smith John M 11 57 Smith Richard M 11 55 Green ; data girls; input name $ age sex $ teacher $; datalines ; Sharice 13 F Smith Mary 12 F Smith
Background image of page 1

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

View Full DocumentRight Arrow Icon
SAS - 2 - Ellen 11 F Green Carol 11 F Green Chris 13 F Smith Claire 12 F Green Raye 13 F Smith ; data allkids; set boys girls; run ; title2 "printout of allkids data set with boys first " ; proc print data = allkids; run ; STAT 6360 printout of allkids data set with boys first Obs name sex age height teacher 1 Tom M 12 62 Smith 2 Bob M 13 57 Green 3 Joe M 11 59 Green 4 Harry M 12 53 Green 5 William M 13 60 Smith 6 John M 11 57 Smith 7 Richard M 11 55 Green 8 Sharice F 13 . Smith 9 Mary F 12 . Smith 10 Ellen F 11 . Green 11 Carol F 11 . Green 12 Chris F 13 . Smith 13 Claire F 12 . Green 14 Raye F 13 . Smith data allkids2; set girls boys; run ; title2 "printout of allkids data set with girls first " ; proc print data = allkids2; run ; STAT 6360 printout of allkids data set with girls first Obs name age sex teacher height 1 Sharice 13 F Smith . 2 Mary 12 F Smith . 3 Ellen 11 F Green . 4
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

Chapter4 - Chapter 4 SAS Chapter 4 Combining SAS Data Sets...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online