Search code examples
sascalculation

SAS Enterprise Guide - Date value syntax error


Hope someone can help me in my case when in SAS EG.

t1.MIN_of_DATE_PARAM  - in date format
t1.MAX_of_DATE_PARAM  - in date format
    CASE WHEN t1.MIN_of_DATE_PARAM < 01JAN2019 AND t1.MAX_of_DATE_PARAM <  01JAN2019
THEN 'OLD CLIENT'  END

how can i compare it to jan12019 which I have declared in the calculation? here's the error i get:

(CASE WHEN t1.MIN_of_DATE_PARAM < 01JAN2019 AND t1.MAX_of_DATE_PARAM <  01JAN2019
THEN 'OLD CLIENT'  END)
                                  _________
                                  22
                                  76

ERROR 22-322: Syntax error, expecting one of the following: 

enter image description here


Solution

  • The error is underlined in the log, you can't specify a date value in SAS simply by putting 01JAN2019, you need to do the following:

    CASE WHEN t1.MIN_of_DATE_PARAM < '01JAN2019'd AND t1.MAX_of_DATE_PARAM <  '01JAN2019'd
    THEN 'OLD CLIENT'  END
    

    Wrapping the values in ''d converts the provided date-string into a SAS date value which can be compared with the date variables. For more information, search the SAS documentation for "SAS Date Constants".