Hi Members,
I am trying to set up a run date base on whether it is holiday or not. The program below is for the date right after holiday only. For example, if the holiday is 09/02/2013, this program will run on 09/03/2013. In this case, it involves a date check, I want to set up RUNDATE to the holiday date (09/02/2013).
ps: since program use today() function, and now is not holiday, so I assume that 06/17/2013 is holiday for testing purpose.
%LET HOLD = '02SEP2013'D ,'17JUN2013'D;
%MACRO CHCK (DATESET=);
DATA TEST;
FORMAT RUNDATE DATE9.;
TO_DAY = TODAY()-1;
%IF &DATESET. = AUTO %THEN %DO;
%IF TO_DAY IN &HOLD. %THEN RUNDATE = TODAY()-1;
%ELSE %IF TO_DAY NOT IN &HOLD. %THEN RUNDATE = TODAY();
%END;
%ELSE RUNDATE = &DATESET.;
PROC PRINT DATA = TEST;
%MEND;
%CHCK(DATESET=AUTO);
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: TO_DAY IN &HOLD.
It seems like I did not use IN operator correctly.
Please help.
Thanks in advance.
You are not using macro conditionals properly. It looks like you just want to use normal IF statement as you want to compare values of a dataset variable (TO_DAY). I also find that it helps to keep the distinction if you intent the macro statements independently of the indentation of the actual SAS statements.
%MACRO CHCK (DATESET=);
DATA TEST;
FORMAT TO_DAY RUNDATE DATE9.;
TO_DAY = TODAY()-1;
%IF &DATESET. = AUTO %THEN %DO;
IF TO_DAY IN (&HOLD) THEN RUNDATE = TO_DAY;
ELSE RUNDATE=TO_DAY+1;
%END;
%ELSE %DO;
RUNDATE = &DATESET.;
%END;
RUN;
PROC PRINT DATA = TEST;
RUN;
%MEND CHCK;
80 %LET HOLD = '02SEP2013'D ,'17JUN2013'D;
81 %CHCK(DATESET=AUTO);
MPRINT(CHCK): DATA TEST;
MPRINT(CHCK): FORMAT TO_DAY RUNDATE DATE9.;
MPRINT(CHCK): TO_DAY = TODAY()-1;
MPRINT(CHCK): IF TO_DAY IN ('02SEP2013'D ,'17JUN2013'D) THEN RUNDATE = TO_DAY;
MPRINT(CHCK): ELSE RUNDATE=TO_DAY+1;
MPRINT(CHCK): RUN;
...
82 %CHCK(DATESET='01JAN2013'D);
MPRINT(CHCK): DATA TEST;
MPRINT(CHCK): FORMAT TO_DAY RUNDATE DATE9.;
MPRINT(CHCK): TO_DAY = TODAY()-1;
MPRINT(CHCK): RUNDATE = '01JAN2013'D;
MPRINT(CHCK): RUN;
Common question, one link with the answer is above, many others on here or via google.
Hi Reeza,
Thanks for your link. I have checked online, but I didn't see an example involve date in IN operator.
It would be great if you have any reference that have date involved.
Thanks again.
If that's in a data step it doesn't need to be a macro if/then, it can be standard SAS dataste if/then (no %).
Also the IN can be a standard IN, not a %in .
You are not using macro conditionals properly. It looks like you just want to use normal IF statement as you want to compare values of a dataset variable (TO_DAY). I also find that it helps to keep the distinction if you intent the macro statements independently of the indentation of the actual SAS statements.
%MACRO CHCK (DATESET=);
DATA TEST;
FORMAT TO_DAY RUNDATE DATE9.;
TO_DAY = TODAY()-1;
%IF &DATESET. = AUTO %THEN %DO;
IF TO_DAY IN (&HOLD) THEN RUNDATE = TO_DAY;
ELSE RUNDATE=TO_DAY+1;
%END;
%ELSE %DO;
RUNDATE = &DATESET.;
%END;
RUN;
PROC PRINT DATA = TEST;
RUN;
%MEND CHCK;
80 %LET HOLD = '02SEP2013'D ,'17JUN2013'D;
81 %CHCK(DATESET=AUTO);
MPRINT(CHCK): DATA TEST;
MPRINT(CHCK): FORMAT TO_DAY RUNDATE DATE9.;
MPRINT(CHCK): TO_DAY = TODAY()-1;
MPRINT(CHCK): IF TO_DAY IN ('02SEP2013'D ,'17JUN2013'D) THEN RUNDATE = TO_DAY;
MPRINT(CHCK): ELSE RUNDATE=TO_DAY+1;
MPRINT(CHCK): RUN;
...
82 %CHCK(DATESET='01JAN2013'D);
MPRINT(CHCK): DATA TEST;
MPRINT(CHCK): FORMAT TO_DAY RUNDATE DATE9.;
MPRINT(CHCK): TO_DAY = TODAY()-1;
MPRINT(CHCK): RUNDATE = '01JAN2013'D;
MPRINT(CHCK): RUN;
Thanks Tom, this works for me.
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.
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.