Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hans Baumgartner Penn State University

Similar presentations


Presentation on theme: "Hans Baumgartner Penn State University"— Presentation transcript:

1 Hans Baumgartner Penn State University
Introduction to SAS Hans Baumgartner Penn State University

2 TITLE 'reading data from the command file'; DATA check1; INPUT id x1 x2 x3 x4 $ x5 x6; label id='respondent_id'; cards; /* or 'datalines;' */ 1xx1xx2xx3 a b c d ; DATA check1; set check1; proc print; var id x1-x6; proc corr; var x1 x2; run;

3 TITLE 'three ways of reading in data from an external file: 1st method'; DATA check2; infile 'd:\m554\DataScreening\data.dat'; INPUT id x1 x2 x3 x4 $ x5 x6; proc print; var id x1-x6; run; TITLE 'three ways of reading in data from an external file: 2nd method'; DATA check3; INPUT id 1 x1 3-4 x2 6-7 x #2 x4 $ 3-4 x5 6-7 x6 9-10; TITLE 'three ways of reading in data from an external file: 3rd method'; DATA check4; INPUT (id x1 x2 x3 x4 x5 x6) (1.0,3*3.0/$4.0,2*3.0);

4 TITLE 'two ways of creating a file containing a subset of the original variables'; DATA check1a; set check1(keep=id x1 x2 x3); proc print; DATA check1b; set check1(drop=x4 x5 x6); run; TITLE 'selecting a subset of the original data with an if statement'; DATA check2a; set check2; if id<3;

5 TITLE 'recoding, transforming, creating variables, etc
TITLE 'recoding, transforming, creating variables, etc.'; DATA check3a; set check3; if id<3 then group=-1; else group=1; lnx1=log(x1); logx1=log10(x1); sqrtx1=sqrt(x1); x1x2=x1*x2; arcsinx1=arsin(sqrt(x1/20)); mx123a=(x1+x2+x3)/3; mx123b=mean(x1,x2,x3); if x6=99 then x6=.; if x1<=10 or x2>=10 then s1=1; else s1=0; if x1<=10 and x2>=10 then s2=1; else s2=0; if x1 ne x2 then s3=1; else s3=0; proc print; run;

6 TITLE 'renaming variables in a data set';
DATA check1a; set check1a(rename=(x1=x11 x2=x12 x3=x13)); proc print; run; TITLE 'combining two files by appending one to the other'; DATA new1; set check1a check1a; TITLE 'combining two files by merging observations based on a common variable'; DATA new2; merge check1a check1b; by id; TITLE 'writing (a subset of) data to an external file'; DATA check1; set check1; file 'd:\m554\DataScreening\data.out'; put x1 x2 x3; /* ods rtf close; */ quit;


Download ppt "Hans Baumgartner Penn State University"

Similar presentations


Ads by Google