BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nithin_kp
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

3 REPLIES 3
Astounding
PROC Star

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;

Tom
Super User Tom
Super User

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;
nithin_kp
Calcite | Level 5

Thanks both of you; Included both the options, now it's working fine.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 4531 views
  • 1 like
  • 3 in conversation