Date: Tue, 10 Jul 2007 02:30:20 -0400
Reply-To: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject: Re: macro not resolved in sql select
...note that parameters are ALWAYS local! If you really want / need to
work with global variables, you should not use the same name than for a
On Mon, 9 Jul 2007 22:49:58 -0700, David L Cassell <davidlcassell@MSN.COM>
>jay.li.yin@GMAIL.COM wrote back:
>>On Jun 30, 8:06 pm, jay.li....@gmail.com wrote:
>> > The exact code that I wrote is as follows.
>> > %global num;
>> > %macrocmr(num);
>> > data table0;
>> > set tableA;
>> > v&num=vA; /* VA is a variable in tableA */
>> > %mend cmr;
>> > %cum(3);
>> > /* Since I invoke themacrocmr here, themacrovariable num, which is
>> > defined as global, should take the value 3 now, isn't it? */
>> > /* Then I did the following */
>> > procsql;
>> > create table t2 as
>> > selectt0.v&num, t1.*
>> > from table0 as t0 left join table1 as t1
>> > on t0.date= t1.date;
>> > ERROR: Column v could not be found in the table/view identified with
>> > the correlation name t0
>> > NOTE:
>>OK, I figured it out.
>>Macro parameters are always local even if I globalize them. So they
>>cannot be resolved after the macro finishes execution.
>That's not really accurate.
>First, global macro variables are generally a bad idea, and often reflect
>poor database design or poor program design. Sometimes they reflect
>poor planning of the external system into which the SAS program falls,
>forcing you to do what you didn't want.
>Second, you *can* make information available outside the macro.
>Otherwise, they would be useless. How could you ever get anything
>You have to think of these thingies as basic text substitution (with
>some exceptions of course). You're making all of this way too complex.
>If you would explain to SAS-L just what you *really* need, someone
>could probably show you a much cleaner approach.
>David L. Cassell
>3115 NW Norwood Pl.
>Corvallis OR 97330
>Need a brain boost? Recharge with a stimulating game. Play now!