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

I am trying to transpose from wide to long because I have 30 variables (dx1-dx30) which I'd like to put into one column with a different row for each dx variable. I want all other variables in that dataset copied for each row for those dx variables. I was able to do most of this (my dx variables worked the way I want them to and it created a new row for each of them etc) but the other variables which I'd like copied into the other rows are only being filled into the first row. In the rows for dx2-dx30, it just has a period for the other variables.

 

This is the code I have:

 

Proc transpose data=totranspose2016 out=transposed2016 name=diagnosis prefix=code;
By uniqueadmission;
copy patientuhin cdiff primary readmit agecat died; /*want these copied to each corresponding row but only shows on first row for each
uniqueadmission number, then has a period for these variables in all the other rows*/
Var dx1-dx30; /*I want these to go from being 30 different columns to one column with one row for each dx number - this part worked*/
Run;

 

Is it possible to change this so the variables listed in the copy statement are copied to all of the corresponding rows?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Does UNIQUEADMISSION have a different value on every observation?

If so then just add any other variable you want kept the same as extra BY variables after it.

If you want the new variable to be named CODE instead of CODE1 (or COL1) use a RENAME= dataset option on the output dataset.

Proc transpose data=totranspose2016 out=transposed2016(rename=(code1=code))
  name=diagnosis prefix=code
;
  by uniqueadmission  patientuhin cdiff primary readmit agecat died;
  var dx1-dx30;
run;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Does UNIQUEADMISSION have a different value on every observation?

If so then just add any other variable you want kept the same as extra BY variables after it.

If you want the new variable to be named CODE instead of CODE1 (or COL1) use a RENAME= dataset option on the output dataset.

Proc transpose data=totranspose2016 out=transposed2016(rename=(code1=code))
  name=diagnosis prefix=code
;
  by uniqueadmission  patientuhin cdiff primary readmit agecat died;
  var dx1-dx30;
run;

 

Geoghegan
Obsidian | Level 7
Perfect, thank you! That fixed it!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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