LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: To: Chang Chung <chang_y_chung@HOTMAIL.COM>

Hi Chang,

Or how about this variant (without RESOLVE):

========= %let mvar = 7;

data _null_; v = " "; do i = 1 to 5; CALL EXECUTE ('%let mvar=%eval(&mvar+1);'); v = SYMGET ('mvar'); put i= v=; end; run; =========

Result in log: ========= i=1 v=8 i=2 v=9 i=3 v=10 i=4 v=11 i=5 v=12 =========

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_; SET ......; * suppose character variable Element has the list elements; CALL EXECUTE ('%LET MacList = &MacList ' || Element || ';'); RUN; %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) http://www.vitatron.com, http://home.hccnet.nl/jim.groeneveld

My computer always teaches me something new I thought I knew already.

[common disclaimer]

On Fri, 19 Aug 2005 13:35:42 -0400, Chang Chung <chang_y_chung@HOTMAIL.COM> wrote:

>On Fri, 19 Aug 2005 11:47:15 -0400, Ed Heaton <EdHeaton@WESTAT.COM> wrote: > >>Jim, >> >>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. > >Hi, Ed, > >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 step. > >Cheers, >Chang > >%symdel mvar; >%let mvar = 7; > >data _null_; > v = " "; > do i = 1 to 5; > v = resolve('%let mvar=%eval(&mvar. +1); &mvar'); > put i= v=; > end; >run; >/* on log >i=1 v=8 >i=2 v=9 >i=3 v=10 >i=4 v=11 >... >i=5 v=12 >*/


Back to: Top of message | Previous page | Main SAS-L page