Date: Wed, 22 Apr 2009 15:35:47 -0400
Reply-To: D T <sasandstats@LIVE.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: D T <sasandstats@LIVE.COM>
Subject: macro question-using list of variables?
Content-Type: text/plain; charset="iso-8859-1"
SAS-L,
I have been stuck with this several times before--can you suggest how to resolve this?
I have 7 variables in a data set I need to use as by variables on a proc means, and I need to create means from 4 variables in the same data set. This sounds like it should be resolvable in a macro because it is so repetitive.
I can create a macro for which I would subsequently switch out the means variable, and the by variables, but I have not been able to figure out how to feed the two sets of variables to two lists that a macro would run through, and use one variable after the other.
Here is a simplified example of my data:
data a;
input sex $ p agroup rgroup $ system $ loc $ time meas1 meas2 meas3 meas4;
cards;
F 1 2 W C1 R 1 3 5 1 2
F 0 2 W C3 U 3 1 1 2 1
M 0 2 B C2 U 2 4 7 2 3
F 0 3 W C2 R 1 3 3 7 5
M 0 4 O C1 U 1 1 3 5 2
;
I can get a simple macro together like this:
%MACRO means(varnm,Bvarnm);
proc sort data=a;
by &bvarnm;
run;
proc means data=a;
by &bvarnm;
var &varnm;
title "means by &bvarnm for &varnm";
RUN;
%MEND;
%means(meas1,sex)
%means(meas1,agroup)
%means(meas1,rgroup)
etc.... until I have created means for meas1-meas4 by all 7 by groups (sex-time).
But isn't there a way that I could make a macro loop through my list of by variables, and run a proc means with each of the 7 by variables, and run through a second list of my four meas variables?
Thanks for your help!
D.T.
_________________________________________________________________
Rediscover HotmailŪ: Now available on your iPhone or BlackBerry
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Mobile2_042009