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

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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).

View solution in original post

10 REPLIES 10
collinelliot
Barite | Level 11

Are you using the "MINOPERATOR" option?

x2PSx
Calcite | Level 5

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

Reeza
Super User

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);
x2PSx
Calcite | Level 5

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

Reeza
Super User

@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.

x2PSx
Calcite | Level 5

I work with SAS 9.3 TS Level 1M1 W32_7PRO

Reeza
Super User

MINDELIMITER has been available as of SAS 9.2+

Astounding
PROC Star

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).

x2PSx
Calcite | Level 5

That is a very nice shortcut indeed for my specific problem, thank you

Tom
Super User Tom
Super User

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;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1460 views
  • 0 likes
  • 5 in conversation