Hi, I am looking to be able to set a custom interval and then create month dummies for observations with a macro. I am running into problems with the comparison of dates. In addition to what is below, I have also tried using quotes around the macro date variables and using the %sysevalf-function with %if-%then-%else -structure (and both at the same time). In the %sysevalf-case the date comparison is just always true or false. Below is my code: %macro date_loop(start,end);
data WORK.x7;
set work.x99;
%let start=%sysfunc(inputn(&start,anydtdte9.));
%let end=%sysfunc(inputn(&end,anydtdte9.));
%let dif=%sysfunc(intck(month,&start,&end));
%do i=0 %to &dif;
%let date=%sysfunc(intnx(month,&start,&i,b),date9.);
%let date2=%sysfunc(intnx(month,&start,&i,e),date9.);
if mydate1 <= &date2. AND mydate2 >= &date. then
%do;
if employed = 'true' then p&i. = 1;
if dummy = 'true' then p&i. = 1;
%end;
else %do;
p&i. = 0;
%end;
%end;
run;
%mend date_loop;
%date_loop(01jan2019,01jan2020); which results in following errors ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN,
LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.
ERROR 388-185: Expecting an arithmetic operator.
ERROR 76-322: Syntax error, statement will be ignored. I would be grateful for any help!
... View more