- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 09-21-2021 12:41 PM
(1100 views)
Dear,
I need suggestion in Proc transpose step. Please suggest to get the out put needed.
data one;
input trt$ aval$ nobs pct;
datalines;
a complete 10 20
a disconti 20 40
b complete 20 40
b disconti 10 20
;
output need;
aval a_nobs b_nobs a_pct b_pct
complete 10 20 20 40
disconti 20 10 40 20
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And sometimes a double transpose is needed for extra wide data sets:
https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd
You need a double transpose. Do it first to get NOBS and PCT into a single row and then a second transpose to get it wide, using both TRT + variable_name (NOBS/TRT) as your ID to get them together.
FYI - if you calculated this from PROC MEANS you may be able to modify that proc to do this in that same step instead of doing it after the fact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data one;
input trt$ aval$ nobs pct;
datalines;
a complete 10 20
a disconti 20 40
b complete 20 40
b disconti 10 20
;
proc sort data=one;
by aval;
run;
proc transpose data=one out=want suffix=_nobs;
by aval;
id trt;
var nobs;
run;
proc transpose data=one out=want2 suffix=_pct;
by aval;
id trt;
var pct;
run;
data want3;
merge want(in=a drop=_name_) want2( drop=_name_);
by aval;
run;
Thanks,
Jag
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want a report, consider this:
proc sort data=one;
by aval trt;
run;
proc transpose data=one out=trans;
by aval;
id trt;
var nobs pct;
run;
proc report data=trans;
column aval _name_,(a b);
define aval / group;
define _name_ / "" across;
define a / sum;
define b / sum;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data one;
input trt$ aval$ nobs pct;
datalines;
a complete 10 20
a disconti 20 40
b complete 20 40
b disconti 10 20
;
proc transpose data=one out=temp(index=(aval));
by trt aval;
var nobs pct;
run;
proc transpose data=temp out=want(drop=_name_) delimiter=_;
by aval;
var col1;
id trt _name_;
run;