BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

In my data the variables are presented as "height" height_raw" height_std" height_UN" height_STD_UN" BMi" bmi_raw" bmi_std" bmi_UN" bmi_STD_UN". I need to transpose the variables.  I did transpose using my code. I want to know if there is a way to simplify the code.

Thank you.

 

data

 

ID  height(N)   height_std(C)   height_UN   height_STD_UN  BMi (N)  bmi_raw(C)  bmi_std(C)   bmi_UN   bmi_STD_UN    dt

 

 1     76              190                   in                cm                       35          35                    35               kg/m2      kg/m2         2015-01-02

 

Output need;

 

ID   Test                N         C         S            U        SU                dt

 

  1   HEIGHT         76        76       190        IN         CM            2015-06-22

   1    BMI               35        35         35    kg/m2      kg/m2      2015-06-22    

 

MYCODE;      

 

proc transpose data=ONE out=TWO (drop= _LABEL_ rename =(_name_=VSTESTCD col1=VSORRES));
by id dt;
var bmi height;
run;

 

I peroformed Proc transpose on other variables  (bmi_raw  height_raw) 4 more times and merged by ID and dt variables to get the output I need.

 

 

Is there a way to simplify the code. Thank you.

5 REPLIES 5
Cynthia_sas
SAS Super FREQ
My tendency would be to use a DATA step program and one or more than one ARRAY statements. Or, possibly you wouldn't need an array. Not sure about ARRAY, am sure about DATA step.

cynthia
Cynthia_sas
SAS Super FREQ
Also, I am not sure about why N and C are the same value in your desired output. The way I read your INPUT data (the original), height(N) is 76 and height_std(C) is 190, not 76? So why do N and C both have the same values???
cynthia
knveraraju91
Barite | Level 11

Thanks for the reply. N means Numeric and C means chracter forms.

Reeza
Super User

Your tables don't come across clearly in the forum. 

Can you please format them so it's easier to see what you're trying to do?

I don't think a proc transpose will work.  

 

If you could provide data as a datastep that's even better ... typing out your data means a lot of people will just skip on to the next question.

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

knveraraju91
Barite | Level 11

Sorry. There is charcter  varaibale missing in the data.

 

data

 

ID  h(N)    h(C)   h_std(C)   h_UN   h_STD_UN  BMi (N)  bmi_raw(C)  bmi_std(C)   bmi_UN   bmi_STD_UN    dt

 

 1     76   76        190           in                cm         35          35                 35               kg/m2      kg/m2         2015-01-02

 

Output need;

 

ID   Test                N         C         S            U        SU                dt

 

  1   HEIGHT         76        76       190        IN         CM            2015-06-22

   1    BMI               35        35         35    kg/m2      kg/m2      2015-06-22    

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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