BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Paul_NYS
Obsidian | Level 7

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

art297
Opal | Level 21

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;

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 9209 views
  • 0 likes
  • 3 in conversation