Hi All,
I have an output like below:
group | Coefficient | pvalue |
Toddler | 0.5 | 0.003 |
Young | 0.7 | 0.005 |
Child | 0.6 | 0.21 |
I want to transpose the ouput like this:
Toddler_Coeff | Toddler_Pvalue | Young_Coeff | Young_Pvalue | Child_Coeff | Child_Pvalue |
0.5 | 0.003 | 0.7 | 0.005 | 0.6 | 0.21 |
But when I use proc transpose, the output like this:
| Toddler | Young | Child |
Coefficient | 0.5 | 0.7 | 0.6 |
pvalue | 0.003 | 0.005 | 0.21 |
here is my part code:
proc transpose data=final_1 out=final_1 ;
var coefficient pvalue;
id group;
run;
Any way to help?
Thanks,
C
Use two steps.
proc sort data=have; by group ; run;
proc transpose data=have out=middle ;
by group;
var Coefficient pvalue ;
run;
proc transpose data=middle out=want delimiter=_;
id group _name_;
var col1;
run;
PROC TRANSPOSE could do something like that. It would take a few steps, and generate different names (such as Coeff_Young instead of Young_Coeff).
For such a small data set, I would suggest coding it yourself. For example:
data want;
do until (done);
set have end=done;
if group='Toddler' then do; Toddler_Coeff = coefficient; Toddler_Pvalue = pvalue; end;
else if group='Young' then do; Young_Coeff=coefficient; Young_Pvalue = pvalue; end;
else do; Child_Coeff = coefficient; Child_Pvalue = pvalue; end;
end;
drop group coefficient pvalue;
run;
Thanks, that helps!
Use two steps.
proc sort data=have; by group ; run;
proc transpose data=have out=middle ;
by group;
var Coefficient pvalue ;
run;
proc transpose data=middle out=want delimiter=_;
id group _name_;
var col1;
run;
Thanks, that really helps!!!
Coincidence? I actually had occasion to use this technique today. Made me look like a magician. Awesome!
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.
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.