Date: Thu, 8 Mar 2012 08:24:41 -0500
Reply-To: Quentin McMullen <qmcmullen.sas@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Quentin McMullen <qmcmullen.sas@GMAIL.COM>
Subject: Re: Using IN operator in a macro XXXX
In-Reply-To: <201203081149.q285eePZ021895@waikiki.cc.uga.edu>
Content-Type: text/plain; charset=us-ascii
Hi,
I don't think it's a dumb question at all. Oddly (to me at least) whoever developed the macro language decided that operative would not have % signs.
So you have:
%if &x = yes and &y = yes %then ;
Arguably, life might have been easier (less need for macro quoting) if that were:
%if &x %= yes %and &y %= yes %then %;
So in the pseudo code, every macro token starts with a %. Even the macro semicolon starts with a %.
To some, the pseudo code might look ugly (so many % signs!). But others might prefer benefit of less need to quote things like OR IN AND ; .
--Q.
On Mar 8, 2012, at 6:49 AM, KarlK <karlstudboy@HOTMAIL.COM> wrote:
> I know that a macro "IN" construct was on the SAS ballot for a long time,
> and it's great, but I've been curious about one thing. (Disclaimer, I
> didn't search the archives to see if this issue has been discussed
> previously.) Any idea why we ended up with this complicated system of
> parens vs. no parens, MINOPERATOR option and MINDELIMETER option as
> opposed to their just implementing it as a "%IN" operator? Wouldn't %IN be
> more consistent with the rest of the macro language, e.g., %DO %WHILE, %IF
> %THEN %ELSE, etc.?
>
> Sorry if this is a dumb question.
>
> Karl
>
> On Wed, 7 Mar 2012 18:16:02 -0500, Arthur Tabachneck <art297@ROGERS.COM>
> wrote:
>
>> And, according to the examples shown in the documentation, it can be used
>> with or without parentheses:
>> http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/vi
> ew
>> er.htm#a003092012.htm
>>
>> Art
>> ------
>> On Wed, 7 Mar 2012 16:13:13 -0500, Dan Abner <dan.abner99@GMAIL.COM>
> wrote:
>>
>>> Hi Mary,
>>>
>>> Honestly, I wondered about that too. I was just using the example code
>>> on the SAS website at:
>>>
>>> http://support.sas.com/kb/35/591.html
>>>
>>> As Joe made clear, I had failed to use the MINDELIMITER = option in
>>> the %MACRO statement. It works now (without the ()).
>>>
>>>
>>>
>>> On Wed, Mar 7, 2012 at 3:49 PM, Mary Rosenbloom
>>> <mary.rosenbloom.sas@gmail.com> wrote:
>>>> When I looked at this code, the first thing that jumped out at me is
> that
>> I
>>>> usually use parenthesis with IN, and surround the arguments with quotes
>>>> (unless they are numeric). How is it that you are getting away with
> not
>>>> using them:
>>>>
>>>> %IF %SUBSTR(&VAR1,1,2) IN R_,Q_,O_,N_ %THEN %LET YES = 1;
>>>>
>>>> vs
>>>>
>>>> %IF %SUBSTR(&VAR1,1,2) IN ("R_","Q_","O_","N_") %THEN %LET YES = 1;
>>>>
>>>> Thanks for your comments! I know I'm missing the boat on this, but
> can't
>>>> figure out why.
>>>>
>>>> Cheers,
>>>> Mary R.
>>>>
>>>> On Wed, Mar 7, 2012 at 12:40 PM, Dan Abner <dan.abner99@gmail.com>
> wrote:
>>>>>
>>>>> That did it! Thanks Joe!
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Mar 7, 2012 at 3:37 PM, Joe Matise <snoopy369@gmail.com>
> wrote:
>>>>>> I think the MINDELIMITER defaults to %STR( ) [ie, space]. You need
> to
>>>>>> use
>>>>>> spaces or change MINDELIMITER to , I believe.
>>>>>>
>>>>>> -Joe
>>>>>>
>>>>>>
>>>>>> On Wed, Mar 7, 2012 at 2:34 PM, Dan Abner <dan.abner99@gmail.com>
>> wrote:
>>>>>>>
>>>>>>> Hi everyone,
>>>>>>>
>>>>>>> I am attempting to use the IN operator at the macro level,
> however,
>>>>>>> it is not producing the desired/expected results. I was expecting
> the
>>>>>>> macro variable YES's value to be changed from 0 to 1. I have the
>>>>>>> following code:
>>>>>>>
>>>>>>> ===
>>>>>>>
>>>>>>>
>>>>>>> %LET VAR1 = Q_VARIABLE;
>>>>>>>
>>>>>>>
>>>>>>> %MACRO TEST();
>>>>>>> OPTIONS MINOPERATOR;
>>>>>>>
>>>>>>> %LET YES = 0;
>>>>>>>
>>>>>>> %IF %SUBSTR(&VAR1,1,2) IN R_,Q_,O_,N_ %THEN %LET YES = 1;
>>>>>>>
>>>>>>> %PUT SUBSTR = %SUBSTR(&VAR1,1,2);
>>>>>>> %PUT YES = &YES;
>>>>>>>
>>>>>>> %MEND;
>>>>>>>
>>>>>>> %TEST()
>>>>>>>
>>>>>>>
>>>>>>> * =============================================================;
>>>>>>>
>>>>>>> I am getting in the log:
>>>>>>>
>>>>>>> ====
>>>>>>>
>>>>>>> 85
>>>>>>> 86 %LET VAR1 = Q_VARIABLE;
>>>>>>> 87
>>>>>>> 88
>>>>>>> 89 %MACRO TEST();
>>>>>>> 90 OPTIONS MINOPERATOR;
>>>>>>> 91
>>>>>>> 92 %LET YES = 0;
>>>>>>> 93
>>>>>>> 94 %IF %SUBSTR(&VAR1,1,2) IN R_,Q_,O_,N_ %THEN %LET YES = 1;
>>>>>>> 95
>>>>>>> 96 %PUT SUBSTR = %SUBSTR(&VAR1,1,2);
>>>>>>> 97 %PUT YES = &YES;
>>>>>>> 98
>>>>>>> 99 %MEND;
>>>>>>> 100
>>>>>>> 101 %TEST()
>>>>>>> MLOGIC(TEST): Beginning execution.
>>>>>>> MLOGIC(TEST): %LET (variable name is YES)
>>>>>>> MLOGIC(TEST): %IF condition %SUBSTR(&VAR1,1,2) IN R_,Q_,O_,N_ is
>> FALSE
>>>>>>> MLOGIC(TEST): %PUT SUBSTR = %SUBSTR(&VAR1,1,2)
>>>>>>> SUBSTR = Q_
>>>>>>> MLOGIC(TEST): %PUT YES = &YES
>>>>>>> YES = 0
>>>>>>> MLOGIC(TEST): Ending execution.
>>>>>>>
>>>>>>> ===
>>>>>>>
>>>>>>> Any ideas why this is not working?
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> Dan
>>>>>>
>>>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Cheers,
>>>> Mary F. O. Rosenbloom
>>>> http://www.sascommunity.org/wiki/User:Otterm1
>>>>
|