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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.