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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

5 REPLIES 5
Reeza
Super User

http://www.amadeus.co.uk/sas-technical-services/tips-and-techniques/macro/using-the-in-operator-with...

Common question, one link with the answer is above, many others on here or via google.

Belle
Obsidian | Level 7

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.

Reeza
Super User

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 .

Tom
Super User Tom
Super User

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;

Belle
Obsidian | Level 7

Thanks Tom, this works for me.

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!

How to Concatenate Values

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.

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
  • 2732 views
  • 0 likes
  • 3 in conversation