Desktop productivity for business analysts and programmers

Proc Transpose

Accepted Solution Solved
Reply
New Contributor Hi1
New Contributor
Posts: 4
Accepted Solution

Proc Transpose

I need your help to transpose the data as attached in the file.

 

 


Accepted Solutions
Solution
‎02-04-2016 02:16 AM
Super User
Super User
Posts: 7,720

Re: Proc Transpose

[ Edited ]

You have a few options (to note, if you want proper code, please post test data in the form of a datastep, we don't have time to type data in from a spreadsheet).

Proc transpose * 4 one for each of your variables by famid, then merge the resulting datasets back together byfamid

Eg.

proc transpose data=have out=want1 prefix=year;

  by famid;

  var year;

run;

... same again for each variable

data want;

  merge want1-want4;

  by famid;

run;

 

Also, Arrays - by group, retainall values, array for each varible output on last row.

 

View solution in original post


All Replies
Solution
‎02-04-2016 02:16 AM
Super User
Super User
Posts: 7,720

Re: Proc Transpose

[ Edited ]

You have a few options (to note, if you want proper code, please post test data in the form of a datastep, we don't have time to type data in from a spreadsheet).

Proc transpose * 4 one for each of your variables by famid, then merge the resulting datasets back together byfamid

Eg.

proc transpose data=have out=want1 prefix=year;

  by famid;

  var year;

run;

... same again for each variable

data want;

  merge want1-want4;

  by famid;

run;

 

Also, Arrays - by group, retainall values, array for each varible output on last row.

 

Respected Advisor
Posts: 3,788

Re: Proc Transpose

For this multiple variable to all wide transpose named by OBS number, I think the easiest method is PROC SUMMARY IDGROUP. You do have to know the maximum number of obs per by group and that can't exceed 100.  In other words this work for your example.  I suppose you will reveal the full story in time.

 

data fam;
   input famid year faminc Age Inc @@;
   cards;
1 96 40000 67 12 1 97 40500 33 44 1 98 41000 59 59 2 96 45000 57 80 2 97 45400 47 59 2 98 45800 49 71 3 96 75000 76 84 3 97 76000 10 48 3 98 77000 22 45
;;;;
   run;
proc print;
   run;
proc summary data=fam;
   by famid;
   output out=wide(drop=_: famid_:) idgroup(out[3](_all_)=);
   run;
proc print;
   run;

Capture.PNG

New Contributor Hi1
New Contributor
Posts: 4

Re: Proc Transpose

Thanks for ur response

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 475 views
  • 0 likes
  • 3 in conversation