How to find average column values ​​in SAS

I have a SAS dataset, let's say:

No d1 d2 d3 ... dn
1  2  3  4 ... n1
2  3  4  5 ... n2
3  4  5  6 ... n3

Now I need to find the average values ​​of all columns in SAS. Is there any way to do this?

The number of columns is not specific. If I need the average values ​​of the columns d1- dn, then the expected result:

3 4 5 ..  (n1+n2+n3)/3

Is there a way to do this, Either at the data stage, or using proc sql or proc iml?

+3
source share
4 answers

Assuming all of your required variables begin with d, you can use the colon wildcard operator to select all of them. Here I used PROC SUMMARY, it is identical to PROC MEANS with the NOPRINT option. Obviously this is a very minor change to the answer from @pteranodon

proc summary data=have nway;
var d: ;
output out=want (drop=_:) mean=;
run;
+4
source

proc means - .

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;

drop = , .

+5

Yes, in the data step you should use something like this mean(OF d1-d100). Pay attention to the ofinside function. This is a symbolic link in which the average value of columns d1, d2, d3, ..., d100 is calculated

+2
source

You can use PROC MEANS, for example,

PROC MEANS DATA = indata; 
VAR d1-dn; 
OUTPUT=outdata MEAN=m1-mn; 
RUN;
+1
source

All Articles