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

Hi all,

when running this

data tests;

      set allofit;

      %macro anotherloop(start,stop);

      %do n = &start. %to &stop.;

            opendate_&n. > actual_inception_date and

      %end;

      %mend anotherloop;

      if %anotherloop(start=0,stop=1); opendate_2 < actual_inception_date;

run;

, SAS tells me there's a syntax error. What I'm trying to get to is this:

if opendate_0 > actual_inception_date and

opendate_1 > actual_inception _date and

...

opendate_27  > actual_inception_date and opendate_2 actual_inception_date;

Any help would be greatly appreciated.

thanks,

Marco

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Do not write a semicolon after the macro invocation. That semicolon breaks your if condition because it is not part of the macro invocation but part of the "normal" program code.

if %anotherloop(start=0,stop=1) opendate_2 < actual_inception_date;

View solution in original post

5 REPLIES 5
Astounding
PROC Star

The problem lies in switching between keyword and positional parameters in your macro.  If  you leave the macro definition as is, call it using:

%anotherloop (0,1)

Alternatively, you could change the macro definition to:

%macro anotherloop (start=, stop=);

Then you could leave the macro call as is.

Good luck.

Kurt_Bremser
Super User

Do not write a semicolon after the macro invocation. That semicolon breaks your if condition because it is not part of the macro invocation but part of the "normal" program code.

if %anotherloop(start=0,stop=1) opendate_2 < actual_inception_date;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Just thinking out-loud, but would you not be better off finding the smallest date from opendate, then comparing that to actual_inception_date?  E.g.:

proc sql;

     create table WANT as

     select     A.*

     from       HAVE A

     left join   (select MIN(OPENDATE) as MIN_OPEN_DATE from HAVE group by **grouping variables**) B

     on          A.**grouping variables** = B.**grouping variables**

     where     B.MIN_OPEN_DATE > A.ACTUAL_INCEPTION_DATE;

quit;

This way if there is one date below the inception date, you know the rest of the if are going to fail (as they are all AND), and if the minimum is > inception date then the if will pas as none could be lower.

Astounding
PROC Star

Something along those lines occurred to me, but you do have to watch out for missing values.  MIN will ignore them, so the DATA step logic could perform differently.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry to re-post on this, I just wanted to correct myself as you are using transposed data rather than horizontal.  Use datastep with:

data want;

     set have;

     if min(of opendate_1-opendate27) > actual_inception_date then output;

run;

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 5 replies
  • 1729 views
  • 6 likes
  • 4 in conversation