Solved
Contributor
Posts: 27

# proc means in a macro/ do loop/ array

hi guys

I would like to exploit the mean for the variables m1 to m20 and put the results in a different dataset for each variables. ex. m1 mean in db1, m2 mean in db2 etc.

proc means data=a  N  SUM; var m1; output out=db1 N=N SUM=SUM ;run;

I could do it with macro calls, but i guess it would we faster with a "do" loop or array.

do you have an idea on how i could do it?

thanks a lot!

Accepted Solutions
Solution
‎01-24-2014 09:04 AM
Posts: 3,852

## Re: proc means in a macro/ do loop/ array

I would not want all my data in separate data sets.  Maybe it would be good if you could explain more about what you will do with the data.

I find the data set produced by these statement to be very useful.  You might consider it.

proc means data=sashelp.class n sum stackods;

class sex;
ods select none;

ods output Summary=Summary;

run;
ods select all;
proc print;

run;

All Replies
Solution
‎01-24-2014 09:04 AM
Posts: 3,852

## Re: proc means in a macro/ do loop/ array

I would not want all my data in separate data sets.  Maybe it would be good if you could explain more about what you will do with the data.

I find the data set produced by these statement to be very useful.  You might consider it.

proc means data=sashelp.class n sum stackods;

class sex;
ods select none;

ods output Summary=Summary;

run;
ods select all;
proc print;

run;
Occasional Contributor
Posts: 17

## Re: proc means in a macro/ do loop/ array

Hello,

One can simply use hyphen operator in var (or by, class, among others)

var m1-m20

to appoint sequentially named variables

and

N(m1-m20)=x1-x20

to rename N and SUM variables explicitly.

Here's my worked test code in SAS 9.3 x64 environment:

data a;

input m1 m2 m3 @@;

datalines;

1 2 3 4 5 6 7 8 9

;

run;

proc means data=a N SUM /*noprint*/;

var m1-m3;

output out=a_means

N(m1-m3)=N_m1-N_m3 SUM(m1-m3)=SUM_m1-SUM_m3;

run;

Of course, if you don't need html output, simply uncomment the "noprint" option. Hope this helps.

Bill

🔒 This topic is solved and locked.