How can i change a data in wide format for the following data format by source.
ID source cp resp
1 a 1 0.1
1 a 2 0.5
1 b 1 0.3
1 b 2 0.2
2 a 1 0.15
2 a 2 0.7
2 b 1 0.8
2 b 2 0.4
into a format
ID cp resp_a resp_b
1 1 0.1 0.5
1 2 0.3 0.2
2 1 0.15 0.7
2 2 0.8 0.4
Thank you!
You can use proc tranpose for that, very simple:
proc tranpose data=have out=want prefix=resp_; by id cp; var resp; id source; run;
Note assumes sorted by the by variables. Post test data in the form of a datastep next time.
Also, unless this is for a report output, it is really not recommended to program in this way, it will make all your program from that point on much harder, and you have increased the difficulty even more by affixing a character as the end, thus you will struggle to even use lists and such like, e.g. var1, var2, can be a list of var:.
You can use proc tranpose for that, very simple:
proc tranpose data=have out=want prefix=resp_; by id cp; var resp; id source; run;
Note assumes sorted by the by variables. Post test data in the form of a datastep next time.
Also, unless this is for a report output, it is really not recommended to program in this way, it will make all your program from that point on much harder, and you have increased the difficulty even more by affixing a character as the end, thus you will struggle to even use lists and such like, e.g. var1, var2, can be a list of var:.
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.