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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 367 views
  • 0 likes
  • 3 in conversation