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
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;
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.
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;
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.
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.
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;
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!
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.