DATA Step, Macro, Functions and more

Transpose data

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 96
Accepted Solution

Transpose data

Hi there,

I am trying to crreate a table having summary of report submitted in each month and experiencing some problem. Can somebody help me to overcome the obstacle. Sample of the table,  I am havcing as well as I am expecting are given below. Thank you in advance for your kind reply. 

data have;
input id mon $ count ;
cards;
101 jan 10
101 feb 20
101 mar 25
101 jun 20
102 jan 10
102 feb 20
102 Apr 25
102 may 20
103 Apr 10
103 feb 20
103 mar 25
103 may 20
103 jul 25
;
run;


data want;
input id jan feb mar apr may jun jul;
cards;
101 10 20 25 . . 20 .
102 10 20 . 25 20 . .
103 . 20 25 10 20 . 25
;
run;

Regards,

 

Swain

Accepted Solutions
Solution
‎01-31-2017 03:55 PM
Super User
Posts: 5,081

Re: Transpose data

Often, a good tool to transpose data is PROC TRANSPOSE:

 

proc transpose data=have out=want (drop=_name_);

var count;

id mon;

by id;

run;

 

The documentation describes the purpose of each of the statements.

 

View solution in original post


All Replies
Solution
‎01-31-2017 03:55 PM
Super User
Posts: 5,081

Re: Transpose data

Often, a good tool to transpose data is PROC TRANSPOSE:

 

proc transpose data=have out=want (drop=_name_);

var count;

id mon;

by id;

run;

 

The documentation describes the purpose of each of the statements.

 

Frequent Contributor
Posts: 96

Re: Transpose data

Thank you for your valuable reply.

Regards,

Swain
Super User
Posts: 10,497

Re: Transpose data

Of course if you are generating a report then perhaps a report procedure is in order.

 

proc report data=have nowd;
   column id (mon, count);
   define id/group;
   define mon/across;
   define count/analysis ;
run;
Frequent Contributor
Posts: 96

Re: Transpose data

Thank you for providing an alternative approach. Appreciated. 

 

Regards,

Swain
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 151 views
  • 3 likes
  • 3 in conversation