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:.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: