Hello guys,
I have data like this below. I want it in the format in the second table below. My current code is as simple as below. Is there any way of creating transposed variables like Desc_A, Desc_B instead of Desc_1, Desc_2?...
Would highly appreciate your response..
Regards
Proc transpose data = have out= data1 prefix=Desc_;
by patientID;
var description;
run;
Have:
| patientID | Description |
| 1 | A |
| 1 | B |
| 1 | C |
| 2 | A |
| 2 | TTT |
Want:
| patientID | Desc_A | Desc_B | Desc_C | Desc_TTT |
| 1 | 1 | 1 | 1 | |
| 2 | 1 | 1 |
OR
Want:
| patientID | Desc_A | Desc_B | Desc_C | Desc_TTT |
| 1 | A | B | C | |
| 2 | A | TTT |
Instead of:
| patientID | Desc_1 | Desc_2 | Desc_3 | Desc_4 |
| 1 | ||||
| 2 |
data have;
input patientID Description $;
cards;
1 A
1 B
1 C
2 A
2 TTT
;
Proc transpose data = have out= data1 prefix=Desc_;
by patientID;
id description;
var description;
run;
Hi There, Actually, the values to be transposed are the "Description" values so it is okay to be either the exact same values as original description or it could be 1...
Want:
| patientID | Desc_A | Desc_B | Desc_C | Desc_TTT |
| 1 | 1 | 1 | 1 | |
| 2 | 1 | 1 |
OR
Want:
| patientID | Desc_A | Desc_B | Desc_C | Desc_TTT |
| 1 | A | B | C | |
| 2 | A | TTT |
data have;
input patientID Description $;
cards;
1 A
1 B
1 C
2 A
2 TTT
;
Proc transpose data = have out= data1 prefix=Desc_;
by patientID;
id description;
var description;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.