- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi guys,
I am new to SAS and got stuck with something :
When I try to do this
%LET SITE=CBH;
%if &site. in AMH, AUH, BSB, CBH, INM, MNL, SGH, VNM %then %do;
%END;
and execute the code, in the log I observe that the condition is failing,
SYMBOLGEN: Macro variable SITE resolves to CBH
MLOGIC(ALN): %IF condition &site. in AMH, AUH, BSB, CBH, INM, MNL, SGH, VNM is FALSE
When I did the same thing in a different place, like
%if ^(&site in DAK, NZM, SEL) %then %do;
%end;
then it worked fine. Can you help me with this issue. Thanks in advance
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Macro language is quite fussy about using the IN operator. Because there are no quotes around values, you have to tell macro language what delimiter to use, and you cannot add spaces between values (unless a space is your delimiter of course). For example:
%LET SITE=CBH;
options mindelimiter=',' ;
%if &site. in AMH,AUH,BSB,CBH,INM,MNL,SGH,VNM %then %do;
%END;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Macro language is quite fussy about using the IN operator. Because there are no quotes around values, you have to tell macro language what delimiter to use, and you cannot add spaces between values (unless a space is your delimiter of course). For example:
%LET SITE=CBH;
options mindelimiter=',' ;
%if &site. in AMH,AUH,BSB,CBH,INM,MNL,SGH,VNM %then %do;
%END;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Did you set the options that allow the macro processor to treat the text IN as an operator instead just treating it like any other text string?
MINDELIMITER= Specifies the character delimiter for the macro IN operator. NOMINOPERATOR Disables IN logical operators in expressions.
Or if your code is inside a macro did you set the option on the %MACRO statement to enable the IN operator?
MINDELIMITER='single character'; specifies a value that will override the value of the MINDELIMITER= global option. The value must be a single character enclosed in single quotation marks and can appear only once in a %MACRO statement. Restriction The following characters cannot be used as a delimiter % & ' " ( ) ; MINOPERATOR | NOMINOPERATOR specifies that the macro processor recognizes and evaluates the mnemonic IN and the special character # as logical operators when evaluating arithmetic or logical expressions during the execution of the macro. The setting of this argument overrides the setting of the NOMINOPERATOR global system option. The NOMINOPERATOR argument specifies that the macro processor does not recognize the mnemonic IN and the special character # as logical operators when evaluating arithmetic or logical expressions during the execution of the macro. The setting of this argument overrides the setting of the MINOPERATOR global system option.
Also I think that the () are required.
So if MINOPERaTOR is set and MINDELIMITER is set to ',' then this should work.
%if &site. in (AMH,AUH,BSB,CBH,INM,MNL,SGH,VNM) %then %do;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks both of you; Included both the options, now it's working fine.