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.
Thanks for the reply. N means Numeric and C means chracter forms.
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.