Unit_4 - Introduction to SAS Programming STSCI501 Fall 2007...

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

View Full Document Right Arrow Icon
1 Introduction to SAS Programming STSCI501 – Fall 2007 Simona Despa Cornell Statistical Consulting Unit (CSCU)
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Part 4 Modifying and Combining SAS Data Sets Overview Set: concatenate, interleave Merge: one–to-one, one-to-many Proc Transpose: reshaping data sets
Background image of page 2
3 The SET Statement Read a SAS data set to: Add new variables Subset the data Concatenation (stack two ore more SAS data sets together) Interleaving (using a BY statement after the SET statement to have the resulting data set interleaved by the value of the BY variable. Sort the data sets to be interleaved by the variable(s) listed in the BY statement.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Example Data Data set name Class: has 19 observations (only 10 presented here) Obs Name Sex Age Height Weight 1 Alfred M 14 69.0 112.5 2 Alice F 13 56.5 84.0 3 Barbara F 13 65.3 98.0 4 Carol F 14 62.8 102.5 5 Henry M 14 63.5 102.5 6 James M 12 57.3 83.0 7 Jane F 12 59.8 84.5 8 Janet F 15 62.5 112.5 9 Jeffrey M 13 62.5 84.0 10 John M 12 59.0 99.5
Background image of page 4
5 SET: Example Add variables To read the data from Class into a new data set : Data Study ; /* name of new data set Study*/ Set Class ; /* Class is name of old SAS data set we read in */ heightSQ=height**2 ; /* create Height squared */ BMI=(weight/heightSQ)*703; /* create BMI variable */ run ;
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 SET: Example Add variables If no new data set is to be created, but modify current data set only: Data and Set statements use the same name of the SAS data file Data Class ; Set Class ; heightSQ=height** 2 ; /*create Height squared*/ BMI=(weight/heightSQ)* 703 ; /* create BMI variable*/ run ;
Background image of page 6
7 SET Height SQ and BMI added Obs Name Sex Age Height Weight HeightSQ BMI 1 Alfred M 14 69.0 112.5 4761.00 16.6115 2 Alice F 13 56.5 84.0 3192.25 18.4986 3 Barbara F 13 65.3 98.0 4264.09 16.1568 4 Carol F 14 62.8 102.5 3943.84 18.2709 5 Henry M 14 63.5 102.5 4032.25 17.8703 6 James M 12 57.3 83.0 3283.29 17.7715 7 Jane F 12 59.8 84.5 3576.04 16.6115 8 Janet F 15 62.5 112.5 3906.25 20.2464 9 Jeffrey M 13 62.5 84.0 3906.25 15.1173 10 John M 12 59.0 99.5 3481.00 20.0944
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 SET Statement: Changing Variable Names RENAME can be used to change the variable’s name data agesx; set class; Rename SEX=GENDER ; run; Obs Name Gender Age BMI 1 Alfred M 14 16.6115 2 Alice F 13 18.4986 3 Barbara F 13 16.1568 4 Carol F 14 18.2709 5 Henry M 14 17.8703
Background image of page 8
9 SET Statement –Subset the data set Subsetting observations: data agesxM; Set class; If Gender=“M” ; run; data agesxF; Set class; If Gender=“F” ; run;
Background image of page 9

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

View Full DocumentRight Arrow Icon
AgesxM AgesxF Obs Name Ge nd er Age Height Weight 1 Alfred M 14 69.0 112.5 2 Henry M 14 63.5 102.5 3 James M 12 57.3 83.0 4 Jeffrey M 13 62.5 84.0 5 John M 12 59.0 99.5 6 Philip M 16 72.0 150.0 7 Robert M 12 64.8 128.0 8 Ronald M 15 67.0 133.0 9 Thoma s M 11 57.5 85.0 10 William M 15 66.5 112.0 Obs Name Gen der Age Height Weight 1 Alice F 13 56.5 84.0 2 Barbara F 13 65.3 98.0 3 Carol F 14 62.8 102.5 4 Jane F 12 59.8 84.5 5 Janet F 15 62.5 112.5 6 Joyce F 11 51.3 50.5 7
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 38

Unit_4 - Introduction to SAS Programming STSCI501 Fall 2007...

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

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