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
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.