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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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