Reputation: 1764
I have a simple proc means procedure and I wish to limit the output to complete rows only.
data test_dat;
input group $ subgroup $ time variable1 variable2;
cards;
A xxxx 1 100 2.50
A xxxx 2 200 2.50
A xxxx 3 300 2.50
A xxxx 4 100 3.00
A zzzz 1 500 1.00
A zzzz 2 450 1.00
A zzzz 3 700 1.50
A zzzz 4 600 1.50
B yyyy 1 200 4.00
B yyyy 2 100 5.00
B yyyy 3 300 4.00
B yyyy 4 250 5.00
;
run;
proc means data=test_dat mean sum;
class group subgroup;
var variable2 variable1;
output out=stuffout(drop=_type_ _freq_ dropme ohheidropme2plz) mean=variable2_mean dropme sum=ohheidropme2plz variable1_sum;
run;
By default, proc means is giving me 9 rows of output, when I only want three (rows 7-9). I know that I can do another data step to eliminate these rows, but know that there has to be a more elegant way. (ps--it won't always be rows 7-9, so that won't work as a general solution).
Thanks
Upvotes: 1
Views: 400
Reputation: 420
Looks like what you're looking for is the proc means nway
option. See here: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000146729.htm
proc means data=test_dat mean sum nway;
class group subgroup;
var variable2 variable1;
output out=stuffout(drop=_type_ _freq_ dropme ohheidropme2plz) mean=variable2_mean dropme sum=ohheidropme2plz variable1_sum;
run;
You could also achieve the same results by using the types or ways statements.
Here you could use ways 2;
, which is saying show all combinations of possible pairs of your class variables. The keyword nway simply specifies that ways = n, where n is the number of class variables you have. By default, proc means includes all possible rows that represent totals (e.g. sum and mean for a given value of your group variable, irrespective of subgroup variable). Ways 2
specifies that you are interested only in those rows that have exactly two of your class variables, which in this case is all of them.
Upvotes: 5