I need your help to transpose the data as attached in the file.
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.
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.
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;
Thanks for ur response
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.