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 (July 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 8 Jul 2004 12:14:56 -0400
Reply-To:     Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject:      Re: Problem with macro logical condition : passing a counter in
              the macro

Paul explains well the issues, and these are things one must understand in order to use the macro facility with confidence.

However, you might find yourself moving in the direction of a quick fix by simply removing the percent signs in your Condition 1 and Condition 2 blocks.

On Thu, 8 Jul 2004 01:33:20 -0400, Paul M. Dorfman <sashole@BELLSOUTH.NET> wrote:

>Dominic, > >You are trying to use a macro assembling Data step code based on the value >of a Data step variable before the Data step has run. Note that the entire >activity of your macro compilation ends before the SAS Supervisor starts >even compiling the Data step, let alone running it. Besides, it would be >extremely contrived to base macro compilation on different values through >which a Data step variable goes as the step runs, and that would require the >step running *before* the macro compilation time. Your COUNT in the %IF >macro statement is nothing else but pure text, not depending in the least on >the value of the variable COUNT in the Data step executing SAS code the >macro had assembled before the step started running. The actual code you >macro assembles (together with the rest of the Data step code), as you can >judge from MPRINT listing, is > >data test ; > > set random ; > > count = _n_ ; > > check = count ; > > lagx1 = lag1(x) ; > > lagx2 = lag2(x) ; > > lagx3 = lag3(x) ; > > lagx4 = lag4(x) ; > > lagx5 = lag5(x) ; > > x_ma_5 = mean (of lagx1 - lagx5) ; > >run ; > >From that you can plainly see if this is the SAS code you want to execute. >First, try to envision the code you want you macro to put together, then >think of the macro as a logical means of putting it together. > >Kind regards, >---------------- >Paul M. Dorfman >Jacksonville, FL >---------------- > >> -----Original Message----- >> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On >> Behalf Of Dominic Mitchell >> Sent: Thursday, July 08, 2004 1:08 AM >> To: SAS-L@LISTSERV.UGA.EDU >> Subject: Problem with macro logical condition : passing a >> counter in the macro >> >> Hi, >> >> >> >> I have that little piece of code as an example (see below). >> In the macro 'ma_create' I want to use the variable count >> that is created in the data step 'test'. Basically count in >> that exemple is set to _n_. >> >> I know that count is seen correctly in the macro because I >> generate the variable check is has the right value. Still >> logical operation that requires the value of count fail. In >> execution of the macro, count is always seen as greater than >> the macro variable days which is set in that example to 5. >> >> Why does the code only excute condition 1 (count is always >> seen as greater than 0)? How can I force the code to satisfy >> the condition >> >> >> Thanks for any suggestion. >> >> >> >> >> data random; >> drop n; >> do n=1 to 100; >> x=floor(exp(rannor(314159)*.8+1.8)); >> output; >> end; >> run; >> >> options mlogic mprint; >> %macro ma_create(name=,days=); >> >> check=count; >> >> %do i=1 %to &days.; >> lag&name.&i.=lag&i.(&name); >> %end; >> >> /*condition 1 */ >> %if count gt &days. %then %do; >> &name._ma_&days.=mean(of lag&name.1 - lag&name.&days.); %end; >> >> /*condition 2*/ >> %else %if count le &days. %then &name._ma_&days.=.; >> >> %mend ma_create; >> >> >> >> data test; >> set random ; >> count=_n_; >> %ma_create(name=x,days=5); >> run; >>


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