- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 12-14-2019 10:01 PM
(492 views)
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
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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