Date: Wed, 3 May 2000 16:54:32 -0500
Reply-To: Daryl Travnicek <dat@UNLSERVE.UNL.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Daryl Travnicek <dat@UNLSERVE.UNL.EDU>
Subject: Re: Macro Loop - General
Content-Type: text/plain; charset="us-ascii"
Ian - I read your posting regarding the general macro loop with interest &
wondered if the &cond variable was necessary - I have included sample code
at bottom of this post. Am I missing something?
Daryl
/*
------------------------------
Date: Wed, 3 May 2000 09:49:46 -0700
From: Jean-Pierre Le Cruguel <lecruguel@EPID.JGH.MCGILL.CA>
Subject: Re: Use of %eval and/or %sysevalf
Thanks a lot Ian and others who contributed.
I needed a very general macro, to work with any value, and any increment.
I just adapted it to play with 3 inner loops, it works great.
Those interested can contact me to get the code.
JP
----- Original Message -----
From: "WHITLOI1" <WHITLOI1@westat.com>
To: "JP" <lecruguel@EPID.JGH.MCGILL.CA>; <SAS-L@LISTSERV.UGA.EDU>; "Poul
Ravn Sorensen" <poulravn1@hotmail.com>
Sent: Tuesday, May 02, 2000 10:29 AM
Subject: Re[2]: Use of %eval and/or %sysevalf
> JP,
>
> Loops with noninteger by values are notorious. With that said, here is
code.
>
> %macro loop ( start = 0.1 , stop = 2 , by = 0.1 ) ;
> %local f_x ;
>
> %if %sysevalf(&by > 0) %then %let cond = %nrstr(&f_x <= &stop) ;
> %else
> %if %sysevalf(&by < 0) %then %let cond = %nrstr(&f_x >= &stop) ;
> %else
> %let cond = 0 ;
>
> %let f_x = &start ;
> %DO %while ( %sysevalf(%unquote(&cond)) ) ;
> %put f_x=&f_x ;
> %let f_x = %sysevalf(&f_x + &by ) ;
> %end ;
> %mend loop ;
>
> %loop(start=0.1,stop=2.0,by=.1)
>
> Ian Whitlock <whitloi1@westat.com>
>
> ____________________Reply Separator____________________
> Subject: Re: Use of %eval and/or %sysevalf
> Author: JP <R_E_M_O_V_E_lecruguel@EPID.JGH.MCGILL.CA>
> Date: 5/2/2000 4:47 PM
>
> Hi all,
>
> Sorry Poul, I do not have answers, but I have a similar question.
> I would like to use some non integer macro variables: ex:
> %DO f_x = 0.1 %TO 2 %BY 0.1;
> ...
> Is there an "official" way to do that? I succeeded once with EVAL (using a
> x10 factor) but I need something more robust.
>
> Any idea?
> I am going to check sysevalf.
>
> JP
>
> "Poul Ravn Sorensen" <poulravn1@hotmail.com> wrote in message
> news:8emh34$q9o$1@news1.tele.dk...
> > Hi people,
> >
> > I haven't used the EVAL macro function a lot but am a bit confused. My
old
> > well-worn manuals (v5) mention the use of %EVAL to do simple arithmetics
> on
> > macro variables. Whereas this works in a simpl example I could not get
it
> to
> > work in a more complex case. Search in the help files (v.6.12) gives
> nothing
> > on %EVAL; instead %SYSEVALF is found.
> >
> > Now my question is: Do I use %EVAL or %SYSEVALF in v.6.12?
> >
> > I can forward examples, but for now the answer to this will be helpfull
> >
> > Thanks in advance
> >
> > Poul Ravn Sorensen
> > Copehagen
> > Denmark
> >
> >
------------------------------
*/
%macro loop ( start = 0.1 , stop = 2 , by = 0.1 ) ;
%local f_x ;
%if %sysevalf(&by > 0) %then %let cond = %nrstr(&f_x <= &stop) ;
%else
%if %sysevalf(&by < 0) %then %let cond = %nrstr(&f_x >= &stop) ;
%else
%let cond = 0 ;
%let f_x = &start ;
%DO %while ( %sysevalf(%unquote(&cond)) ) ;
%put f_x=&f_x ;
%let f_x = %sysevalf(&f_x + &by ) ;
%end ;
%mend loop ;
%loop(start=0.1,stop=2.0,by=.1)
*------------------------------------------------------------------;
* DT - my humble attempt...
*------------------------------------------------------------------;
%macro loop1 ( start = 0.1 , stop = 2 , by = 0.1 ) ;
%local g_x n_x ;
%Let n_x = %SysEvalf((&stop-&start)/&by+1) ;
%Put n_x = &n_x by = &by;
%Do i = 1 %to &n_x;
%Let g_x = %SysEvalf(&start+(&i-1)*&by);
%Put g_x = &g_x;
%End;
%mend loop1 ;
%loop1(start=0.01,stop=2.0,by=.01) ;
%loop1;
*------------------------------------------------------------------;
-------------------------
Daryl Travnicek
SAS Programmer / Biometry
103e Miller Hall
Lincoln, NE 68583-0712
- - - - - - - - - - - - -
dat@unlserve.unl.edu
(402) 472-4746
-------------------------