BookmarkSubscribeRSS Feed
stancemcgraw
Obsidian | Level 7

Hello,

 

   I am working on a data set that includes patientID#s, but each patient has multiple responses for one variable. (Multiple cormorbidites and complications, for example). I want to transpose them out so that I don't have extra spaces or repeated PatientIDS. How do I transpose all of these multiple row variables in one step? 

 

So far I have done this:

 

proc sort data=exlap.traumabase3; by PatientNumber; run;

proc transpose data = exlap.traumabase3 out=exlap.traumabase1 (drop=_name_) prefix=Comorbidites;

by PatientNumber;

var Comorbidities ;

 

 

run;

 

*And this transposes too many comorbidities and only transposes one variable at a time. I have about 40 extra with no data listed for some reason (Comorbidities 6-Comorbidites41 have nothing listed).  

 

3 REPLIES 3
Reeza
Super User

I would suggest looking at the macro here:

http://www.sascommunity.org/wiki/A_Better_Way_to_Flip_(Transpose)_a_SAS_Dataset

 

Otherwise your options are to 

1: Multiple proc transpose and merge the results

2: Use a data step array to transpose but you need to know the maximum amount of variables before hand. The macro or option 1 doesn't require the amount before. 

stancemcgraw
Obsidian | Level 7

Ok. I am not familiar with Macros at all so I am going to use multiple transpose steps, however, when I have trasnposed one variable it lists too many:

Cormobidites6-Cormibidites41 and there is no data there... How do I specifiy only Cormorbidites1-Cormobidites5?

Please see attached screenshot with empty columns of comorbidities below...


Screen Shot 2017-01-31 at 3.59.01 PM.png
Reeza
Super User

That means you do have some records that have 41 comorbidities. What do you want to do with those?

You can just drop the variables you don't need after if you want to keep only 5. 

Typically, I've seen 25 or 10 used in these cases.

 

If you post the code you're using we can help with the modifications. 

 

You don't have to write the macro, just use it. If you give the paper a quick read through it's probably the easiest method. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 2245 views
  • 0 likes
  • 2 in conversation