Date: Wed, 24 Jan 2007 15:33:52 -0500
Reply-To: "data _null_;" <datanull@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "data _null_;" <datanull@GMAIL.COM>
Subject: Re: Macro Variable Problem (or should I say, coder problem)
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
This has been discussed lately. You need %NRSTR around the macro call
to delay execution of the entire macro as the %PUT is executed when
the macro is CALL EXECUTEd but the SQL is not executed until the data
step ends. See some of the other threads about CALL EXECUTE, for more
in depth explanation.
call execute('%nrstr(%AgeChange(' || compress(name) || '));' );
On 1/24/07, Lamias, Mark (CDC/CCID/OD) (CTR) <firstname.lastname@example.org> wrote:
> I am working on a piece of macro code that uses "call execute" to loop
> through a dataset and pass parameters to a macro. The macro should then
> execute proc sql statements and place the selected variable into a new
> macro variable (via a select into statement). Then the new macro
> variable should be used throughout the remainder of the macro to be used
> in data manipulations, etc.
> The problem I am running into is that the macro variable that is created
> during the proc sql statement does not seem to change during each call
> to the macro. However, the macro variable DOES seems to change if I
> just hard-code several calls to the macro statement.
> For your reference, I have provided a simplified version of what I am
> trying to do (using the sashelp.class for this example).
> %macro AgeChange(name);
> proc sql noprint;
> select age into :MVage
> %put &MVage;
> data work.looptable;
> set sashelp.class;
> data _null_;
> set work.looptable;
> call execute('%AgeChange(' || compress(name) || ');' );
> If I hard code
> % AgeChange(Alfred);
> % AgeChange(Alice);
> Instead of executing the data _null_ block of code above, I get the
> following as expected in the log:
> However, if I run the data _null_ block of code which should be making
> the same "%AgeChange()" calls to the macro, I do not get these results.
> It appears the macro variables created in the select into statement are
> not resolving correctly after each iteration through the looptable. So
> my question is: how can I get them to resolve correctly (or at least the
> way I'm intending them to) at each iteration?
> Thanks for your help.
> Mark J. Lamias