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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.