Hi
Maybe my problem is very simple, but I can't with this!
I have this data set:
ID | Gender | Disease1 |
44 | 2 | 1390 |
44 | 2 | 1546 |
44 | 2 | 1670 |
57 | 1 | 2980 |
57 | 1 | 1546 |
83 | 2 | 1390 |
I tried with this:
proc traspose data=example out =example1 prefix=disease;
var disease;
by id;
run;
but I want to something like this:
ID | Gender | Disease1_1 | Disease1_2 | Disease1_3 |
44 | 2 | 1390 | 1546 | 1670 |
57 | 1 | 2980 | 1546 | - |
83 | 2 | 1390 | - | - |
How can I do it?
You were close, but your variable is called disease1 .. NOT disease. The following should work:
proc transpose data=example out =example1 (drop=_:) prefix=disease1_; var disease1; by id gender; run;
Art, CEO, AnalystFinder.com
Putting your data in a wide format will make it more difficult to work with in the long run.
It's common, but it's not because it's a good programming method but because it's common....
1. Add an counter variable (1,2,3) so SAS knows the prefix needed and to make each row unique, see link if you need help with this.
2. Then do PROC TRANSPOSE and add the variable to your ID list.
proc transpose data=have out=want prefix=disease_;
by id gender; *you may need to sort as well;
var disease;
id counter;
run;
You were close, but your variable is called disease1 .. NOT disease. The following should work:
proc transpose data=example out =example1 (drop=_:) prefix=disease1_; var disease1; by id gender; run;
Art, CEO, AnalystFinder.com
Thank you very much!
You right, I was close... but I needed a push!
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.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.