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;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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