Date: Fri, 19 Aug 2005 17:50:43 -0400
Reply-To: Jim Groeneveld <jim1stat@YAHOO.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <jim1stat@YAHOO.CO.UK>
Subject: Re: Help with a Macro resolution problem
Or how about this variant (without RESOLVE):
%let mvar = 7;
v = " ";
do i = 1 to 5;
CALL EXECUTE ('%let mvar=%eval(&mvar+1);');
v = SYMGET ('mvar');
put i= v=;
Result in log:
The macro variables clearly are being assigned (and possibly created)
during the data step. SAS code within a CALL EXECUTE is executed delayed,
i.e. after the end of the current data step. I never yet tried mixed code,
but I assume the same applies in that case as well.
I often use this construct to build a list of values from dataset records
into a single macro variable, like:
%LET MacList = ;
DATA ......; * may be _NULL_;
* suppose character variable Element has the list elements;
CALL EXECUTE ('%LET MacList = &MacList ' || Element || ';');
%PUT MacList = &MacList; * or this inside CALL EXECUTE;
Of course the same result can be obtained directly using PROC SQL (SELECT
Element INTO :maclist) as well.
Regards - Jim.
Y. (Jim) Groeneveld, MSc., Biostatistician, Vitatron b.v., NL
Jim.Groeneveld_AT_Vitatron.com (replace _AT_ by AT sign)
My computer always teaches me something new I thought I knew already.
On Fri, 19 Aug 2005 13:35:42 -0400, Chang Chung <chang_y_chung@HOTMAIL.COM>
>On Fri, 19 Aug 2005 11:47:15 -0400, Ed Heaton <EdHeaton@WESTAT.COM> wrote:
>>You CAN use CALL SYMPUT to write a VALUE to the macro symbol table, and
>>you can use SYMGET to retrieve that value from the macro symbol table.
>>However, you CANNOT use the macro variable. Macro variables are only
>>resolved when the DATA step compiles.
>I have seen this admittedly crazy trick before. I think this clearly shows
>the macro variables that are resolved during the execution of the data
>%let mvar = 7;
> v = " ";
> do i = 1 to 5;
> v = resolve('%let mvar=%eval(&mvar. +1); &mvar');
> put i= v=;
>/* on log