Hello, my macro doesn't work the way I want to. So basically this below works perfectly:
%MACRO mymacro() ;
%IF %substr(&n50prc0_aaaamm.,5,2) = 06
%THEN %DO;
[...]
However I would need something like this because I want every trimester to work
%MACRO mymacro() ;
%IF %substr(&n50prc0_aaaamm.,5,2) in (03,06,09,12)
%THEN %DO;
[...]
I tried many different things including different options like MINDELIMITER but nothing seems to work for me. Thank you for your help
Macro language does support an IN operator. As @collinelliot indicated, you need two options properly set, plus the matching syntax in your code. Tedious, but it is possible. (For example, get rid of the parentheses around the list of values.)
An easy workaround for this case might (depending on the range of values) be:
%let two_digits = %substr(&n50prc0_aaaamm.,5,2);
%if &two_digits = &two_digits / 3 * 3 %then %do;
This statement would apply integer arithmetic (truncating remainders).
Are you using the "MINOPERATOR" option?
Yes, with this
options MINOPERATOR;
%MACRO mymacro / MINDELIMITER=",";
%IF %substr(&n50prc0_aaaamm.,5,2) in (03,06,09,12)
%THEN %DO;
[...]
I get this error:
ERROR 13-12: Unrecognized SAS option name, MINOPERATOR.
2 %MACRO RAPPEL_PROD / MINDELIMITER=",";
ERROR: Extraneous information on %MACRO statement ignored.
ERROR: A dummy macro will be compiled.
3
You need single quotes in the MINDELIMITER
This works for me:
%MACRO myMacro(n50prc0_aaaamm=) / mindelimiter=',' minoperator ;
%IF %substr(&n50prc0_aaaamm.,5,2) in (03,06,09,12)
%THEN %DO;
%PUT &n50prc0_aaaamm. -> MATCH;
%END;
%ELSE %DO;
%PUT &n50prc0_aaaamm. -> NO MATCH;
%END;
%MEND myMacro;
%mymacro(n50prc0_aaaamm=199501);
%mymacro(n50prc0_aaaamm=199502);
%mymacro(n50prc0_aaaamm=199503);
%mymacro(n50prc0_aaaamm=199504);
%mymacro(n50prc0_aaaamm=199505);
%mymacro(n50prc0_aaaamm=199506);
%mymacro(n50prc0_aaaamm=199509);
%mymacro(n50prc0_aaaamm=199512);
%mymacro(n50prc0_aaaamm=199513);
thank you, but it doesn't for me. I should mention that I run this SAS code via a secure shell. My first code does work though, but I don't think the options are recognized
@x2PSx then likely Tom has the correct idea, you're working on an older version of SAS that doesn't support MINDELIMITER - which would be pretty old. Did you verify the SAS version? Or are you using WPS? That doesn't work the same either.
I work with SAS 9.3 TS Level 1M1 W32_7PRO
MINDELIMITER has been available as of SAS 9.2+
Macro language does support an IN operator. As @collinelliot indicated, you need two options properly set, plus the matching syntax in your code. Tedious, but it is possible. (For example, get rid of the parentheses around the list of values.)
An easy workaround for this case might (depending on the range of values) be:
%let two_digits = %substr(&n50prc0_aaaamm.,5,2);
%if &two_digits = &two_digits / 3 * 3 %then %do;
This statement would apply integer arithmetic (truncating remainders).
That is a very nice shortcut indeed for my specific problem, thank you
What version of SAS are you using?
791 %put &sysver ; 9.4
You could use a little arithmetic. Try this little test.
%macro test;
%do m=1 %to 12 ;
%let mm=%sysfunc(putn(&m,z2));
%let mod4=%sysfunc(mod(&mm,4));
%put &=m &=mm &=mod4 ;
%if not %sysfunc(mod(&mm,4)) %then %put Found end of quarter ;
%end;
%mend ;
%test;
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.