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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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: