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.);
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.
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.);
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);
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.
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.);
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.
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.);
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?
NOMINOPERATOR
Option nominoperator;
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);
Thank you all!
You are the best. I will test this out right now!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.