Date: Fri, 29 Mar 1996 10:31:09 EST
Reply-To: Cynthia_Stetz_at_NJQA2@PCMAILGW.ML.COM
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Cynthia Stetz <Cynthia_Stetz_at_NJQA2@PCMAILGW.ML.COM>
Subject: Re: Calling Global Variables Conditionally from a Nested Mac
Joe,
You will need to use double ampersands to have the macro variables resolve
the way you want them to. For example; suppose I set some global macro
variables thusly:
%MACRO MACRO1;
GLOBAL WE1 WE2 WE3 WE4 WE5;
DATA _NULL_;
SET TOPSINFO.FISCAL&YY;
/* POPULATE THE GLOBAL MACRO VARIABLES WITH DATASET VALUES */
CALL SYMPUT("WE1",LEFT(PUT(WE1,$4.)));
CALL SYMPUT("WE2",LEFT(PUT(WE2,$4.)));
CALL SYMPUT("WE3",LEFT(PUT(WE3,$4.)));
CALL SYMPUT("WE4",LEFT(PUT(WE4,$4.)));
CALL SYMPUT("WE5",LEFT(PUT(WE5,$4.)));
CALL SYMPUT("NUMWKS",LEFT(PUT(NUMWKS,$1.)));
RUN;
%MEND MACRO1;
And I want to do something to each weekly data set:
/** DEFINE WHAT IS TO BE DONE TO EACH WEEKS DATA **/
%MACRO BYWK(MD);
PROC PRINT DATA=TOPSDATA.DATA&MD; RUN;
%MEND BYWK;
But I want to do it for all the weeks in the month:
/** DEFINE MACRO TO LOOP THROUGH ALL THE WEEK ENDING DATES FOR A MONTH*/
%MACRO ALLWKS;
%DO K = 1 %TO &NUMWKS; * for JAN,96 &NUMWKS = 5;
%BYWK(&&WE&K); * example: when &K resolves to 1, &&WE&K resolves
to 0105, giving %BYWK(0105);
%END;
%MEND ALLWKS;
The resolution of the symbolic &&we&k and its subsequent usage in the
called macro is, I believe, what you are trying to accomplish. Is this at
all helpful?
Cynthia
______________________________ Reply Separator _________________________________
Subject: Calling Global Variables Conditionally from a Nested Macro
Author: Joe Carpenter <jcarpent@GNU.UVM.EDU> at PROFGTWY
Date: 3/29/96 9:28 AM
I would appreciate any help in calling global variables conditionally
from a nested macro. The program structure is similar to the following:
%global COUNT1 COUNT2 COUNT3 COUNT4 COUNT5;
%macro one (parameters);
macro statements;
call symput statements to set up global vars;
invoke macro 2 with parameters 1, 2, 3, 4, or 5, depending on which
global count variable is needed;
%mend macro 1;
%macro2 (countparameter);
%if &count&countparameter > 0 %then %do; e.g., &count3
program statements;
%end;
%mend macro2;
I would appreciate help with the %if statement - how to have the macro
variable be read as &count1 to &count5, depending on invocation.
Joe Carpenter
Data Analyst, Biometry Facility
University of Vermont
(802) 656-0619 email: jcarpent@zoo.uvm.edu