The problem with prefix is that is just creates columns 1->17, printing: 'month1', 'month'2, 'month3', etc. My columns are actually: 1, 2, 3, 4, 5, 6, 12, 18, 24, 30, 36.........66. They need to be printed as is. The above will also print sequential columns 1-20.
Is there a way to print what is actually there?
Paul
Paul,
Hopefully someone else can provide a more straight-forward way of doing this but, based on your original sample data and a very limited number of groupings (they would have to be expanded of course), the following is one way to achieve what I think you want:
proc format;
value timespan
low-0.0834='1 Month'
0.0835-0.167='2 Months'
0.168-0.2501='3 Months'
other='> 3 Months';
run;
data have;
informat cnty_name $20.;
informat description $30.;
informat start_date end_date date9.;
format start_date date9.;
input id cnty_name description agecat4 year start_date end_date;
exitMonthCategory=yrdif(start_date, end_date, 'AGE');
cards;
2 Hopeland Outcome-2940 1 2006 8feb2012 11nov2012
1 Hopeland Outcome-2940 1 2006 8jan2012 11nov2012
3 Hopeland Outcome-2940 2 2006 8aug2012 11nov2012
5 Hopeland Outcome-2940 2 2006 8oct2012 11nov2012
4 Hopeland Outcome-2940 2 2006 8sep2012 11nov2012
1 Nohopeland Outcome-2940 1 2006 8jan2012 11nov2012
2 Nohopeland Outcome-2940 1 2006 8feb2012 11nov2012
3 Nohopeland Outcome-2940 3 2006 8aug2012 11nov2012
4 Nohopeland Outcome-2940 3 2006 8sep2012 11nov2012
5 Nohopeland Outcome-2940 3 2006 12oct2012 11nov2012
;
proc freq data=have noprint;
tables cnty_name*agecat4*exitMonthCategory/out=test;
format exitMonthCategory timespan.;
run;
options validvarname=any;
proc transpose data=test out=want (drop=_label_
rename=(_name_=DataElement));
by cnty_name agecat4;
id exitMonthCategory;
run;
data want;
retain cnty_name agecat4 DataElement
'1 Month'n
'2 Months'n
'3 Months'n
'> 3 Months'n;
set want;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.