Hi everyone,
I am creating a macro variable that holds a date, and I want to have it display as a date9 format to be used in a title. My code is:
%global cutdt ;
%global cutdtc;
%let cutdt = %sysfunc(mdy(08,15,2024));
%let cutdtc = %sysfunc(inputn(&cutdt, yymmdd10.), date9.);
However, my log gives me the following messages:
5033 %global cutdt ;
5034 %global cutdtc;
5035 %let cutdt = %sysfunc(mdy(08,15,2024));
5036 %let cutdtc = %sysfunc(inputn(&cutdt, yymmdd10.), date9.);
WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is
out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The
result of the operations have been set to a missing value.
Can anyone help me troubleshoot my issue in line 5036? I appreciate any help! Thanks!
The %SYSFUNC() macro function allows you to specify the format to use when converting the value generated by the function it is calling into text to be passed back.
%let cutdt = %sysfunc(mdy(08,15,2024),date9.);
Your mistake was treating the digits string representing the integer value SAS uses for 15AUG2014 as if it was in YYYY-MM-DD style by trying to read it with the YYMMDD10. informat. If you did want to use the PUTN() format to format a date value there is no need to change the integer value into some other representation.
%let cutdt = %sysfunc(mdy(08,15,2024));
%let cutdtc = %sysfunc(putN(&cutdt, date9.));
Note that if you do have your macro variable in DATE9 style you can easily use it in places where you need an actual date value by using it to generate a date literal.
%let cutdt = %sysfunc(mdy(08,15,2024),date9.);
title "Data before &cutdt";
proc print data=have;
where date < "&cutdt"d ;
run;
The %SYSFUNC() macro function allows you to specify the format to use when converting the value generated by the function it is calling into text to be passed back.
%let cutdt = %sysfunc(mdy(08,15,2024),date9.);
Your mistake was treating the digits string representing the integer value SAS uses for 15AUG2014 as if it was in YYYY-MM-DD style by trying to read it with the YYMMDD10. informat. If you did want to use the PUTN() format to format a date value there is no need to change the integer value into some other representation.
%let cutdt = %sysfunc(mdy(08,15,2024));
%let cutdtc = %sysfunc(putN(&cutdt, date9.));
Note that if you do have your macro variable in DATE9 style you can easily use it in places where you need an actual date value by using it to generate a date literal.
%let cutdt = %sysfunc(mdy(08,15,2024),date9.);
title "Data before &cutdt";
proc print data=have;
where date < "&cutdt"d ;
run;
Thank you, Tom! That was a wonderful and clear explanation! I have learned something super useful today.
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.
Ready to level-up your skills? Choose your own adventure.