DATA Step, Macro, Functions and more

%if inside macro

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 82
Accepted Solution

%if inside macro

Hello, 

 

May you help with what is wrong about following macro?  Thank you.   -Ivy 

 

%macro t ;
%let group = 'SORAFENIB_1stline' ;

%if &group. in ( 'SORAFENIB_1stline' , 'commercial', 'Cirrhosis', 'meta') %then %do;
proc sql;
select count(distinct enrolid) into: cntt
from ads.cohort ;
quit;
%end;
%mend;

%t;

 

15 %macro t ;
16 %let group = 'SORAFENIB_1stline' ;
17
18 %if &group. in ( 'SORAFENIB_1stline' , 'commercial', 'Cirrhosis', 'meta') %then %do;
19 proc sql;
20 select count(distinct enrolid) into: cntt
21 from ads.cohort ;
22 quit;
23 %end;
24 %mend;
25
26 %t;
MLOGIC(T): Beginning execution.
MLOGIC(T): %LET (variable name is GROUP)
ERROR: Required operator not found in expression: &group. in ( 'SORAFENIB_1stline' , 'commercial', 'Cirrhosis', 'meta')
ERROR: The macro T will stop executing.
MLOGIC(T): Ending execution.


Accepted Solutions
Solution
‎08-23-2017 04:31 PM
Super User
Posts: 22,846

Re: %if inside macro

MINOPERATOR

 

IN wasn't always supported in SAS macros, so when it was added to keep backwards compatibility it requires you to set the option.

 

You can check the docs on how the specifics work, but you can add it to your macro definition, which is the easiest option.

 

%macro t / MINOPERATOR;

View solution in original post


All Replies
Solution
‎08-23-2017 04:31 PM
Super User
Posts: 22,846

Re: %if inside macro

MINOPERATOR

 

IN wasn't always supported in SAS macros, so when it was added to keep backwards compatibility it requires you to set the option.

 

You can check the docs on how the specifics work, but you can add it to your macro definition, which is the easiest option.

 

%macro t / MINOPERATOR;
Frequent Contributor
Frequent Contributor
Posts: 82

Re: %if inside macro

Thank you very much, Reeza .
Super User
Posts: 6,540

Re: %if inside macro

In addition, you will need to specify what delimiter the IN operator should use.  A comma is permitted as the delimiter, but then you should not have spaces on either side of the commas in your %IF %THEN statement.  The name of the global option is MINDELIMITER:

 

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

 

And you will need to get rid of the parentheses around the list of items.  The macro language IN operator doesn't use them.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 146 views
  • 2 likes
  • 3 in conversation