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

List:       sas-l
Subject:    Re: How to generate a series of variable names from within a macro
From:       Joe Matise <snoopy369 () GMAIL ! COM>
Date:       2009-03-31 13:59:01
Message-ID: b7a7fa630903310659g31b55ddey7c8d0a4ecc391503 () mail ! gmail ! com
[Download RAW message or body]

Well, you're right about not understanding order of execution :)

Simply put, you cannot use %let inside a datastep to change the value of a
macro parameter dynamically.  It's a bit more comples than that, but it's a
good rule of thumb.  %let belongs outside datasteps; call symput works
inside a datastep, but it only can produce one value per macro variable,
available at the end of execution.

You can do a couple of things here:
* Create data set 'down', and keep a tracker (in this case, i) to see how
many periods you have; then call symput that variable to a macro variable,
and in a second data step create 'across'.  In your specific case, doesn't
sound like that's even necessary, as you have &periods available prior to
the datastep.
* Create the month variable from i, using arrays.  This works in your
present syntax.

array months(&periods) month1-month&periods;
... stuff ...
inside the do loop:
months[i] = (whatever months is supposed to have in it);

and the rest roughly like you have it (but give up on the %let l = part).

-Joe


On Tue, Mar 31, 2009 at 8:38 AM, Lane, Jim <jim.lane@rbc.com> wrote:

> Hi, All
>
> I think I'm getting tripped up by not understanding the order of
> execution with macros. I have a bit of macro code to create 2 SAS
> datasets.
>
> %let I = 1;
>  do I=1 to &PERIODS;
>  yyyymm = translate(put(year(m),$4.) || put(month(m),$2.),"0"," ");
>  month&I = plngb;
>  %let I = %eval(&I + 1);
>  output down;
>
>  PLNGB=&BASE+(I*(&BASE*&RATE));
>  m=intnx("month",m,1);
>  end;
>  drop I m;
>  output across;
>
> What I'm trying to do here is create dataset DOWN with &PERIODS
> observations and dataset ACROSS with 1 observation. ACROSS should have a
> series of variables month1, month2, ... For all possible values of I.
>
> DOWN gets created as expected but across only has month1. What do I have
> to do to get &I to increment here?
>
> TIA
>
> -Jim Lane
>
>
> _______________________________________________________________________
>
> This e-mail may be privileged and/or confidential, and the sender does not
> waive any related rights and obligations.
> Any distribution, use or copying of this e-mail or the information it
> contains by other than an intended recipient is unauthorized.
> If you received this e-mail in error, please advise me (by return e-mail or
> otherwise) immediately.
>
> Ce courrier électronique est confidentiel et protégé. L'expéditeur ne
> renonce pas aux droits et obligations qui s'y rapportent.
> Toute diffusion, utilisation ou copie de ce message ou des renseignements
> qu'il contient par une personne autre que le (les) destinataire(s)
> désigné(s) est interdite.
> Si vous recevez ce courrier électronique par erreur, veuillez m'en aviser
> immédiatement, par retour de courrier électronique ou par un autre moyen.
>
[prev in list] [next in list] [prev in thread] [next in thread] 

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