BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

Transpose

I have a dataset like shown below....

meas_ID has a description

for example 101 means temp

102 means BP ete etc

a patient might have different  readings on the same day for the same measID

What is the best way to transpose this dataset

in this example you can take:

101 for Temperature

102 for BP

But I have numerous vitals like that and numerous times....

Thanks

pt_Id     meas_ID      value       name    date

999          101             98.9         bond      23mar2012

999          102           80/120     bond       25mar2012

  999          101            97.6         bond      23mar2012

999            101            97.7        bond       23mar2012 

5 REPLIES 5
robertrao
Quartz | Level 8

Do you think it is a good idea to create a new variable with the descriptions of the meas_ID?

and exporting all Temperature,s across all patients to a seperate dataset and then BP also like that???????

Regards

robertrao
Quartz | Level 8

When I try to do this :

I GET

ERROR: The ID value "_xxxxxxxxx" occurs twice in the same BY group.

proc transpose data=check;

by mrn last_name first_name enc_id admission_date discharged;

var VALUE;

id meas_ID;

run;

Anotherdream
Quartz | Level 8

You get this because by definition an ID with a tranpose step has to be distinct, and yours are not.  NOte that for the same day, you have an id of 101, 101, 101 with 3 different registered values. This will not make sense in a tranpose, because what value would it report for your ID variable of 101?

I do not believe a tranpost is actually what you want, however maybe I am misunderstanding your comments. Would you be able to post a sample of your Before and After data, that way I can better understand what you are asking for?

Did you want the following data output by chance? (I made up my own data, but it gets the point across)

Patient ID     Value

101                    98.6

101                    100.1

101                    101.35

TO become

Patient ID          Value1     Value2     Value3

101                      98.6          100.1        101.35

If so, just add a counter to your dataset (counter=_N_) and then add the counter to your tranpose statement. The order that the data is in will be the order that is maintained amongst your tranposed dataset.

Let me know if this is not what you wanted.

Thanks!

robertrao
Quartz | Level 8

Could you please show how do I adda counter to my transpose step?

Thanks

Anotherdream
Quartz | Level 8

If what I showed was indeed what you needed, you actually don't need an ID step. You can just do the following.

proc sort data=YOURDATA;

meas_id;

run;

proc tranpose data=YOURDATA out=newdata;

by meas_id;

var value;

run;

Let me know if that is not the results you wanted to get.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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