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

Hey all,

 

Quick question, I am trying to get the following to return "yes" and I can't.  I know that I am missing something like a %sysfunc or %syseval or something like that, but just can't figure it out.   I want to be able to have &testid defined as any of the three components of &allids, and have the macro return "yes".

 

Thanks for your help!

 


%let testid = A967;
%let allids = A967 A980 A982;
%put &testid;
%put &allids;

 

%macro johntest(inTestid, inallids);

%if "&inTestid." in "&inallids." %then %do;
%put yes;
%end;
%else %do;
%put no;
%end;

%mend;

%johntest(&testid., &allids.);

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If it's a pop quiz, what do we get if it we get it right?

 

Look at the option MINOPERATOR and note the default setting.

 

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

 

Also, this doesn't make sense.

 

 

%if "&inTestid." in "&inallids." %then %do;

Resolves to :

%if "A967." in "A967 A980 A982" %then %do;

Remember it always needs to be valid SAS code. This isn't. 

 

The following works:

 

option minoperator;
%let testid = A888;
%let allids = "A967" "A980" "A982";
%put &testid;
%put &allids;
 
%macro johntest(inTestid, inallids);
%if "&inTestid." in (&inallids.) %then %do;
%put yes;
%end;
%else %do;
%put no;
%end;
%mend;
%johntest(&testid., &allids.);

 

 

 

 

 

View solution in original post

9 REPLIES 9
collinelliot
Barite | Level 11

 

Minor syntax issues aside, you need the "minoperator" option.


option minoperator;
%let testid = A967;
%let allids = A967 A980 A982;
%put &testid;
%put &allids;

%macro johntest(inTestid, inallids);
%if &inTestid in (&inallids) %then %do;
%put yes;
%end;
%else %do;
%put no;
%end;
%mend;
%johntest(&testid, &allids);

Reeza
Super User

If it's a pop quiz, what do we get if it we get it right?

 

Look at the option MINOPERATOR and note the default setting.

 

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

 

Also, this doesn't make sense.

 

 

%if "&inTestid." in "&inallids." %then %do;

Resolves to :

%if "A967." in "A967 A980 A982" %then %do;

Remember it always needs to be valid SAS code. This isn't. 

 

The following works:

 

option minoperator;
%let testid = A888;
%let allids = "A967" "A980" "A982";
%put &testid;
%put &allids;
 
%macro johntest(inTestid, inallids);
%if "&inTestid." in (&inallids.) %then %do;
%put yes;
%end;
%else %do;
%put no;
%end;
%mend;
%johntest(&testid., &allids.);

 

 

 

 

 

rogerjdeangelis
Barite | Level 11
You need

options minoperator; %macro johntest(inTestid, inallids)/minoperator; SOLUTION %let testid = A967; %let allids = A967 A980 A982; %put &testid; %put &allids; options minoperator; %macro johntest(inTestid, inallids)/minoperator; %if &inTestid. in (&inallids.) %then %do; %put yes; %end; %else %do; %put no; %end; %mend; %johntest(&testid., &allids.); 554 %let testid = A967; 1555 %let allids = A967 A980 A982; 1556 %put &testid; SYMBOLGEN: Macro variable TESTID resolves to A967 A967 1557 %put &allids; SYMBOLGEN: Macro variable ALLIDS resolves to A967 A980 A982 A967 A980 A982 1558 options minoperator; 1559 %macro johntest(inTestid, inallids)/minoperator; 1560 %if &inTestid. in (&inallids.) %then %do; 1561 %put yes; 1562 %end; 1563 %else %do; 1564 %put no; 1565 %end; 1566 %mend; 1567 %johntest(&testid., &allids.); MLOGIC(JOHNTEST): Beginning execution. SYMBOLGEN: Macro variable TESTID resolves to A967 SYMBOLGEN: Macro variable ALLIDS resolves to A967 A980 A982 MLOGIC(JOHNTEST): Parameter INTESTID has value A967 MLOGIC(JOHNTEST): Parameter INALLIDS has value A967 A980 A982 SYMBOLGEN: Macro variable INTESTID resolves to A967 SYMBOLGEN: Macro variable INALLIDS resolves to A967 A980 A982 MLOGIC(JOHNTEST): %IF condition &inTestid. in (&inallids.) is TRUE MLOGIC(JOHNTEST): %PUT yes yes MLOGIC(JOHNTEST): Ending execution.
rogerjdeangelis
Barite | Level 11
If testid can be null 


* fails;
%johntest(%str( ), &allids.);


This works with nulls


if testid can be  null


%let testid = "A967";
%let allids = "A967" "A980" "A982";
%put &testid;
%put &allids;


options minoperator;
%macro johntest(inTestid, inallids)/minoperator;
%if &inTestid. in (&inallids.) %then %do;
%put yes;
%end;
%else %do;
%put no;
%end;
%mend;
%johntest(%str(""), &allids.);

mahler_ji
Obsidian | Level 7

All,

 

Thanks very much for your replies.  One quick thing.

 

Is there a way for me to turn back off this option so that it doesn't inadvertently affect other parts of the code that it shouldn't?

collinelliot
Barite | Level 11

NOMINOPERATOR

Reeza
Super User

Option nominoperator;

ballardw
Super User

You may not have the macro IN operator turned on and possibly have a different delimiter

See if this helps:

 

%macro johntest(inTestid, inallids)/minoperator mindelimiter=' ';
   %if %eval(&inTestid in &inallids) %then %do;
      %put yes;
   %end;
   %else %do;
      %put no;
   %end;
%mend;

%johntest(&testid, &allids);
mahler_ji
Obsidian | Level 7

Thank you all!

 

You are the best.  I will test this out right now!

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
  • 9 replies
  • 2636 views
  • 1 like
  • 5 in conversation