Tuesday, February 13, 2007

quartiles (or x-tiles) for the lazy

data composite;
set data.composite;
proc rank groups=4 out=ranked;
var srcalc srprot sriron srmagnes srphos srzinc srvitc srvitd packyrs bmi;
ranks rank_srcalc rank_srprot rank_sriron rank_srmagnes rank_srphos rank_srzinc rank_srvitc rank_srvitd rank_packyrs rank_bmi;
run;

Sunday, February 11, 2007

create a categorical variable in one fell swoop

categorize a variable with "lazy elegance"

if age ne . then agecat= int(iage/5-1);

make a good looking histogram

More often than would be preferable, it becomes necessary to present data graphically. For a fancy ODS plot of a histogram, try the following:

ods pdf file ="%sysfunc (reverse(%sysfunc(substr(%sysfunc(reverse(%sysfunc(reverse(%scan(%sysfunc(reverse(%sysfunc(getoption(sysin)))),1,/))))),5)))).pdf"; goptions reset=global device=gif ftitle=swissb ftext=swissb htitle=2 htext=2; proc univariate data = alldat2 noprint; title "Histogram for pmh variables"; histogram pmh_dur3 pmh_dur4 pmh_dur5 pmh_dur8 drh_use lst_byirt/cfill=ligr normal cframe=liy barwidth=8 cv=black; inset mean std max min;

ods pdf close;

transpose data

Transpose your data from the so-called "long format" to the ever popular and
occassionally useful "wide format"



proc transpose data=long2 out=widef prefix=faminc;
by famid;
id year;
var faminc;
run;

proc transpose data=long2 out=wides prefix=spend;
by famid;
id year;
var spend;
run;

data wide2;
merge widef(drop=_name_) wides(drop=_name_);
by famid;
run;