SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
monday89
Fluorite | Level 6

Hi, I have the following table

 

categorynametreatmentplacebo
femalefrequency31
femalepercent33.3333.33
malefrequency62
malepercent66.67

66.67

 

I want the following:

 

categorytreatment_frequencytreatment_percentplacebo_frequencyplacebo_percent
female333.33133.33
male666.67266.67

 

I used proc transpose data=test;

by category;

run;

 

i am unable to transpose percent and frequency

 

any help would be appreciated

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

please try the below code 

 

 

proc transpose data=have out=want1 prefix=treatment_;
by category;
var treatment;
id name;
run;

proc transpose data=have out=want2 prefix=placebo_;
by category;
var placebo;
id name;
run;

data want;
merge want1(in=a) want2(in=b);
by category;
run;
Thanks,
Jag
Tom
Super User Tom
Super User

To generate what you want with PROC TRANSPOSE the data needs to be more vertical. So transpose it twice.

proc transpose data=have out=step1 ;
  by category name ;
  var treatment placebo;
run;

proc transpose data=step1 delim=_ out=want(drop=_name_);
  by category ;
  id _name_ name ;
  var col1 ;
run;
                   treatment_     placebo_    treatment_    placebo_
Obs    category     frequency    frequency      percent      percent

 1      female          3            1           33.33        33.33
 2      male            6            2           66.67        66.67

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 493 views
  • 0 likes
  • 3 in conversation