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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

5 REPLIES 5
Astounding
PROC Star

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;

echoli
Obsidian | Level 7

Thanks, that helps!

Tom
Super User Tom
Super User

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;
echoli
Obsidian | Level 7

Thanks, that really helps!!!

Astounding
PROC Star

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 798 views
  • 1 like
  • 3 in conversation