Hi, I have the following table
| category | name | treatment | placebo |
| female | frequency | 3 | 1 |
| female | percent | 33.33 | 33.33 |
| male | frequency | 6 | 2 |
| male | percent | 66.67 | 66.67 |
I want the following:
| category | treatment_frequency | treatment_percent | placebo_frequency | placebo_percent |
| female | 3 | 33.33 | 1 | 33.33 |
| male | 6 | 66.67 | 2 | 66.67 |
I used proc transpose data=test;
by category;
run;
i am unable to transpose percent and frequency
any help would be appreciated
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;
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.