BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
yming954
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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. 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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. 

--
Paige Miller
yming954
Fluorite | Level 6

Thank you very much for your explanation

ballardw
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 477 views
  • 1 like
  • 3 in conversation