Search code examples
sassas-macro

How can I assign minus 1/yesterday from today SAS


I am confused date on SAS.

For example

%let fdate = %sysfunc(today(),EURDFDE9.);

shows 18JUN2019

How about I would like to show yesterday like 17JUN2019

I try to -1 but it did not work,how can I code?


Solution

  • Note that the result of %sysfunc(today(),EURDFDE9.) is the string 18JUN2019. You can't subtract 1 from this. However, today() is a numeric value, so if you store this value instead, you can subtract 1 subsequently. Note that macro variables are stored as string, so even if fdate is a numeric string, you need %eval to do the subtraction.

    %let fdate=%sysfunc(today());
    %put %sysfunc(putn(&fdate,EURDFDE9.));
    %let ydate=%eval(&fdate-1);
    %put %sysfunc(putn(&ydate,EURDFDE9.));