I have SAS codes below:
%let xstart30 = %sysfunc(putn(&nms_omt.-30,yymmddn8.));
The log shows this:
%put &nms_omt.;
20230925
%put &xstart30nms.;
********
I am wondering why there is no value for &xstart30nms.? Thank you
It doesn't work because the value 20230925 is not recognized by SAS as a date! It may be recognized by humans as a date, but not by SAS. You have to convert this value into something that SAS recognizes as a date. Example:
%let nms_omt=20230925;
%let nms_omt1=%sysfunc(inputn(&nms_omt,yymmdd8.));
%put &=nms_omt1;
%put %sysfunc(putn(&nms_omt1,date9.));
%let xstart30 = %sysfunc(putn(&nms_omt1.-30,yymmddn8.));
%put &=xstart30;
SAS dates are the number of days since 01JAN1960. The INPUTN function above reads the date that humans might recognize (20230925) and converts it to the number of days since 01JAN1960 which SAS can recognize as a date. Then all arithmetic (like subtracting 30) and formats (like yymmddn8.) should work.
It doesn't work because the value 20230925 is not recognized by SAS as a date! It may be recognized by humans as a date, but not by SAS. You have to convert this value into something that SAS recognizes as a date. Example:
%let nms_omt=20230925;
%let nms_omt1=%sysfunc(inputn(&nms_omt,yymmdd8.));
%put &=nms_omt1;
%put %sysfunc(putn(&nms_omt1,date9.));
%let xstart30 = %sysfunc(putn(&nms_omt1.-30,yymmddn8.));
%put &=xstart30;
SAS dates are the number of days since 01JAN1960. The INPUTN function above reads the date that humans might recognize (20230925) and converts it to the number of days since 01JAN1960 which SAS can recognize as a date. Then all arithmetic (like subtracting 30) and formats (like yymmddn8.) should work.
Thank you very much for your explanation
To add a detail or two to @PaigeMiller's response.
The largest value that SAS will recognize a date (i.e. number of days from 1Jan1960) is 31DEC20000 (yes 18,000 years in the future) which is 6589335. When you try to manipulated a number like 20230925 you would be dealing something about 3 times larger or in the year 60,000. So none of the SAS date functions recognize the value as a valid date.
Additionally for display none of the current SAS formats will display a year value past 9999
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.