|
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;
>
|