BookmarkSubscribeRSS Feed

Currently my output will display like this

                 Count       Age

Jan 14          12         20-25

Jan 14          66         30-50

Jan 14          67         50+
Feb 14          2          20-25

Feb 14         105        30-50

Feb 14          61         50+

I want it to display

Age    Jan 14      Feb 14

20-25     12              2

30-50     66             105

50+        67             61

Any idea how to do this within my code?

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try

proc sort data=have;

by age;

run;

proc transpose data = have out=want;

by age;

id date;

var count;

run;

Thanks,

Jag

Thanks,
Jag
stat_sas
Ammonite | Level 13

proc tabulate data=have;

class month age;

var count;

table age,month=' '*count=' '*sum=' '*f=8.0;

run;

Ksharp
Super User
data have;
input date & monyy10. Count       Age $;
format date monyy.;
cards;
Jan 14          12         20-25
Jan 14          66         30-50
Jan 14          67         50+
Feb 14          2          20-25
Feb 14         105        30-50
Feb 14          61         50+
;
run;
proc sort data=have(keep=date) out=temp nodupkey;by date;run;
data _null_;
 set temp end=last;
 if _n_ eq 1 then call execute('data want(drop=date); merge ');
 call execute(cats('have(where=(date=',date,') rename=(count=',put(date,monyy.),'))'));
 if last then call execute(';by age;run;');
run;


Xia Keshan

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 464 views
  • 0 likes
  • 4 in conversation