Search code examples
sassas-macro

SAS how to use a macro variable as a date


I have a global macro variable from another macro which looks like '01jan2014' when you print it in the log i.e. there are enforced quotemarks

I want to use this in a proc sql statement but I can't as it doesn't like the variable type.

How do I convert this into a date in the WHERE clause of my proc sql statement?


Solution

  • To convert a date string in DDMONYYYY format, simple add a d to the end.

    '01jan2014'd
    

    will convert the string to a date.

    In your case:

    &var.d
    

    will resolve to

    '01jan2014'd
    

    which will be interpreted as a date.