Search code examples
sqlsas

How to define current year as a variable in proc fedsql


How can I define the current year in proc fedsql? I tried

%let td=%sysfunc(today(),date9.);
%put &td;
%let current_year = year(&td);
%put &current_year;

which doesn't evaluate and

%let td=%sysfunc(today(),date9.);
%put &td;
%let current_year = %eval(year(&td));
%put &current_year;

which gives me the error ERROR: Required operator not found in expression: year(24JUL2023)


Solution

  • Use year(current_date)

    proc fedsql;
        select year(current_date) as "year", *
        from have
        ;
    quit;
    

    Documentation