I have a SAS data set, let's say:
No d1 d2 d3 ... dn
1 2 3 4 ... n1
2 3 4 5 ... n2
3 4 5 6 ... n3
I now need to find the averages of all columns in SAS. Is there a way to do it?
The number of columns is not specific.
If I need the averages of d1
-dn
columns, then the output I expect is:
3 4 5 .. (n1+n2+n3)/3
Is there a way to do this Either in the data step or using proc sql or proc iml?
proc means
is the way to calculate column-wise statistics.
data have;
input No d1 d2 d3 d4;
datalines;
1 2 8 60 80
2 3 12 50 70
3 4 10 40 60
;
run;
proc means data=have noprint nway;
var d1-d4;
output
out=want(drop=_TYPE_ _FREQ_)
mean=;
run;
The drop= clause will exclude the automatic variables for type and frequency if you don't need them.
Assuming all your required variables begin with d, then you can use the colon wildcard operator to select them all. I've used PROC SUMMARY here, this is identical to PROC MEANS with the NOPRINT option. Obviously this is a very minor alteration of the answer from @pteranodon
proc summary data=have nway;
var d: ;
output out=want (drop=_:) mean=;
run;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With