[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: Counter in a Macro
From:       Jim Groeneveld <jim.1stat () YAHOO ! COM>
Date:       2011-05-30 17:57:57
Message-ID: 201105301757.p4UArTqk019301 () waikiki ! cc ! uga ! edu
[Download RAW message or body]

Hi James,

Make it: %Let Counter = %Eval( &Counter + 1 ) ;
a percent sign instead of a dollar sign.

Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician/SAS consultant
http://jim.groeneveld.eu.tf



On Mon, 30 May 2011 12:31:51 -0400, James Algina <algina@UFL.EDU> wrote:

>Hello Toby,
>
>Thank you for your reply.  I tried what you suggested but had not
>provided sufficient details in my first email.  The macro looks like this
>
> > macro xxxx;
>%Let Counter = 0 ;
>   %do A = 1 %to 2;
>   %do B = 1 %to 2;
>
>data;
>if &A=1 then A =.10; else A=.50;
>if &B=1 then B =.10; else B=.50;
>cond=&counter;
>file 'f:\condition.dat' mod;
>put cond 3.0 +1 A 4.2 +1 B 4.2 +1 ;
>run;
>
>%do C = 1 %to 2;
>
>
>additional  program code here
>
>
>  %end;
>%Let Counter = $Eval( &Counter + 1 ) ;
>%end;
>  end;
>%mend xxxx;
>
>The program works the first time the data step is executed.  The second
>time the data step executes the following error is issued:
>SYMBOLGEN:  Macro variable COUNTER resolves to $Eval( 1 + 1 )
>NOTE: Line generated by the macro variable "COUNTER".
>493        $Eval( 1 + 1 )
>            _
>            386
>            200
>            76
>MPRINT(xxxx):   cond=$Eval( 1 + 1 );
>MPRINT(xxxx):   file 'f:\condition.dat' mod;
>MPRINT(xxxx):   put cond 3.0 +1 A 4.2 +1 B 4.2 +1 ;
>MPRINT(xxxx):   run;
>
>ERROR 386-185: Expecting an arithmetic expression.
>
>ERROR 200-322: The symbol is not recognized and will be ignored.
>
>ERROR 76-322: Syntax error, statement will be ignored.
>
>NOTE: The SAS System stopped processing this step because of errors.
>
>
>Is there a way to overcome this problem using the Counter variable?
>
>
>On 5/30/2011 12:39 AM, toby dunn wrote:
>> > macro xxxx;
>> %Let Counter = 0 ;
>> > %do A = 1 %to 2;
>> > %do B = 1 %to 2;
>> > %do C = 1 %to 2;
>> >
>> >
>> > program code here
>>
>> %Let Counter = $Eval( &Counter + 1 ) ;
>> > %end;
>> > %end;
>> > %end;
>> > %mend xxxx;
>>
>>
>> Toby Dunn
>>
>>
>> If you get thrown from a horse, you have to get up and get back on,
>> unless you landed on a cactus; then you have to roll around and scream
>> in pain.
>>
>> �Any idiot can face a crisis�it�s day to day living that wears you out�
>> ~ Anton Chekhov
>>
>>
>>
>>
>> > Date: Sun, 29 May 2011 22:29:26 -0400
>> > From: algina@UFL.EDU
>> > Subject: Counter in a Macro
>> > To: SAS-L@LISTSERV.UGA.EDU
>> >
>> > Hi,
>> >
>> > I have a macro that looks like the following:
>> >
>> > macro xxxx;
>> > %do A = 1 %to 2;
>> > %do B = 1 %to 2;
>> > %do C = 1 %to 2;
>> >
>> >
>> > program code here
>> >
>> > %end;
>> > %end;
>> > %end;
>> > %mend xxxx;
>> >
>> > I would like to add a counter to create a macro variable that would be 1
>> > for A =B=C=1 AND 2 FOR A =B=1 AND C=2 and so forth. Is there a way to
>> > do this?
>> >
>> > Thanks.
>> >
>> >
>> >
>> > --
>> > James Algina
>> > Professor
>> > Research and Evaluation Methodology
>> > 119D Norman Hall
>> > P.O. Box 117047
>> > University of Florida
>> > Gainesville, FL 32611
>
>--
>James Algina
>Professor
>Research and Evaluation Methodology
>119D Norman Hall
>P.O. Box 117047
>University of Florida
>Gainesville, FL 32611
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic