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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3046 views
  • 2 likes
  • 4 in conversation