BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rosegarden81
Obsidian | Level 7

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:

patientIDDescription
1A
1B
1C
2A
2

TTT

 

 

Want:

patientIDDesc_ADesc_BDesc_CDesc_TTT
1 1 1 1 
2 1   1

 

OR

Want:

patientIDDesc_ADesc_BDesc_CDesc_TTT
1 A B C 
2 A  TTT

 

Instead of:

patientIDDesc_1Desc_2Desc_3Desc_4
1    
2    

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20
No values to transpose?
rosegarden81
Obsidian | Level 7

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:

patientIDDesc_ADesc_BDesc_CDesc_TTT
1 1 1 1 
2 1   1

 

OR

Want:

patientIDDesc_ADesc_BDesc_CDesc_TTT
1 A B C 
2 A  TTT

 

 

novinosrin
Tourmaline | Level 20

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;

Reeza
Super User
Use ID statement in PROC TRANSPOSE to specify the variable to be used in the name. Use IDLABEL to specify a variable that’s the label.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1279 views
  • 3 likes
  • 3 in conversation