Sorting variables

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Sorting variables

In my data set, that describes patients and their clinical conditions, I have multiple variables with the same prefix 'ICD', e.g ICDa, ICDb etc. The ICD variables have data which relate to a clinical condition. Each unique patient has their own row with the multiple ICD variables in numerous columns.

I need to create multiple patient rows (i.e. duplicate the unique patient identifier variable) with all ICD variable data in one column called simply ICD.

Is there a simple way to do this?

Many thanks


Accepted Solutions
Solution
‎09-11-2013 07:20 PM
Super Contributor
Posts: 644

Re: Sorting variables

Posted in reply to elliejane

If your existing data only has one row per patient you can use proc transpose

proc transpose

               data = have

               out = want

               ;

by patient ;

var ICD: ;

run ;

Review the doco on transpose as there are options to name the resulting variables.  The default variable _NAME_ will hold the former column name.  You can drop _LABEL_ unless the original dataset has useful labels.

Richard

View solution in original post


All Replies
Solution
‎09-11-2013 07:20 PM
Super Contributor
Posts: 644

Re: Sorting variables

Posted in reply to elliejane

If your existing data only has one row per patient you can use proc transpose

proc transpose

               data = have

               out = want

               ;

by patient ;

var ICD: ;

run ;

Review the doco on transpose as there are options to name the resulting variables.  The default variable _NAME_ will hold the former column name.  You can drop _LABEL_ unless the original dataset has useful labels.

Richard

Contributor
Posts: 62

Re: Sorting variables

Posted in reply to RichardinOz

Sounds like you have many ICD variables for the same patient.

You can use something like this:

proc transpose

          data=have 

          out=want (rename=(col1=ICD));

  by PatientID;

  VAR   ICDa ICDb ICDc ICDd .....etc;

run;

in this way, you will have multiple records per each patient id and have one variable called ICD

New Contributor
Posts: 2

Re: Sorting variables

Posted in reply to RichardinOz

Thank you Richard

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 168 views
  • 0 likes
  • 3 in conversation