BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
park2039
Calcite | Level 5
I am trying to execute the following macro. Can someone explain why both conditions at the bottom are FALSE?
 
Thanks
 
 
%macro run_mig (yr);
data one;
 %if &yr in (2015,2016) %then %do;
  set "/y/x/&yr/vs&yr._1yr" ;
 %end;
 %else %if &yr le 2014 %then %do;
  set "/y/x/&yr/data/vpers&yr._1yr" ;
 %end;
run;
%mend;
 
%run_mig(2015);
 
MLOGIC(RUN_MIG): Beginning execution.
MLOGIC(RUN_MIG): Parameter YR has value 2015
MPRINT(RUN_MIG): data one;
MLOGIC(RUN_MIG): %IF condition &yr in (2015,2016) is FALSE
MLOGIC(RUN_MIG): %IF condition &yr le 2014 is FALSE
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

IN doesn't always work as expected with the logic. 

 

You can enable it using MINOPERATOR.

 

%macro run_mig(yr) / minoperator mindelimiter=',';

Or use OR

 

 %if &yr=2015 or &yr=2016 %then %do;

http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#p0pbehl7wj5sl4n1o...

View solution in original post

4 REPLIES 4
Reeza
Super User

IN doesn't always work as expected with the logic. 

 

You can enable it using MINOPERATOR.

 

%macro run_mig(yr) / minoperator mindelimiter=',';

Or use OR

 

 %if &yr=2015 or &yr=2016 %then %do;

http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#p0pbehl7wj5sl4n1o...

park2039
Calcite | Level 5
Reeza,

OR option worked. The other option minoperator mindelimiter=',' generated the following errors;

ERROR: The /MINDELIMITER= option must be a single character enclosed in single quotation marks.
ERROR: A dummy macro will be compiled.

Thanks

gamotte
Rhodochrosite | Level 12

I think the default delimiter for the in operator in macros is the space.

Try

 

option mindelimiter=",";

 

Astounding
PROC Star

Using the IN operator in macro language is tricky, and requires the proper setting for two options, and possibly a slightly different syntax.  While you can look them up if you would (start with MINDELIMITER), it's easier to just get rid of IN for two possible values:

 

%if &yr=2015 or &yr=2016 %then %do;

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
  • 4 replies
  • 2183 views
  • 2 likes
  • 4 in conversation