DATA Step, Macro, Functions and more

proc transpose output

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 76
Accepted Solution

proc transpose output

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


Accepted Solutions
Solution
‎05-01-2017 02:31 PM
Super User
Super User
Posts: 6,500

Re: proc transpose output

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;

View solution in original post


All Replies
Super User
Posts: 5,084

Re: proc transpose output

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;

Frequent Contributor
Posts: 76

Re: proc transpose output

Thanks, that helps!

Solution
‎05-01-2017 02:31 PM
Super User
Super User
Posts: 6,500

Re: proc transpose output

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;
Frequent Contributor
Posts: 76

Re: proc transpose output

Thanks, that really helps!!!

Super User
Posts: 5,084

Re: proc transpose output

Coincidence?  I actually had occasion to use this technique today.  Made me look like a magician.  Awesome!

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 164 views
  • 1 like
  • 3 in conversation