Date: Wed, 22 Apr 2009 16:03:53 -0400
Reply-To: Jack Clark <jclark@HILLTOP.UMBC.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Clark <jclark@HILLTOP.UMBC.EDU>
Subject: Re: macro question-using list of variables?
In-Reply-To: A<BLU132-W343F234E5FCA8F707BA9D5C8740@phx.gbl>
Content-Type: text/plain; charset="us-ascii"
DT,
Do you have to have separate reports for each BY variable-Measure
combination? If not, consider a CLASS statement with all of your BY
variables, a VAR statement with your measures, and a WAYS statement
requesting only reports on single BY variables (not on the interactions
between BY variables).
proc means data = a;
class sex p agroup rgroup system loc time;
var meas:;
ways 1;
run;
Jack
Jack Clark
Senior Research Analyst
phone: 410-455-6256
fax: 410-455-6850
jclark@hilltop.umbc.edu
University of Maryland, Baltimore County
Sondheim Hall, 3rd Floor
1000 Hilltop Circle
Baltimore, MD 21250
Confidentiality Notice: This e-mail may contain information that is legally privileged and that is intended only for the use of the addressee(s) named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying of this e-mail, distribution, or action taken in reliance on the contents of this e-mail and/or documents attributed to this e-mail is strictly prohibited. If you have received this information in error, please notify the sender immediately by phone and delete this entire e-mail. Thank you.-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of D T
Sent: Wednesday, April 22, 2009 3:36 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: macro question-using list of variables?
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(r): Now available on your iPhone or BlackBerry
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover
_Mobile2_042009