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

Hello,  

I am working with the code below and I'm getting the error. 

 

29 datestr='12Mar202'd;
___________
77
ERROR: Invalid date/time/datetime constant '12Mar202'd.
ERROR 77-185: Invalid number conversion on '12Mar202'd.

30 datestr2='12Mar0202'd;
____________
77
ERROR: Invalid date/time/datetime constant '12Mar0202'd.
ERROR 77-185: Invalid number conversion on '12Mar0202'd.

 

data test;
datestr='12Mar202'd;
datestr2='12Mar0202'd;
run;

I don't know why SAS doesn't accept a 3 digit year. Is there a way to read 3 digit year in SAS?

 

I thank you in advance for your help.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Yes, the Gregorian Calendar went into effect on 15 October 1582, which I think is the earliest date that SAS can handle.

 

Although the tell you the truth, I am surprised anyone needs a date of 12MAR202 in SAS, as there are so few historical records from back then to indicate something happened on a specific date.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

If you mean the year 202 which was over 1,800 years ago, I don't think SAS can work with calendars that far in the past.

 

If you mean something else, then explain what 202 means.

--
Paige Miller
kelxxx
Quartz | Level 8
data test;
datestr='01JAN1581'd;
datestr2='01JAN1582'd;
run;


Yes, that's it, it's the year 202.
I just did a test, and the error shows up from 1581.

 

PaigeMiller
Diamond | Level 26

Yes, the Gregorian Calendar went into effect on 15 October 1582, which I think is the earliest date that SAS can handle.

 

Although the tell you the truth, I am surprised anyone needs a date of 12MAR202 in SAS, as there are so few historical records from back then to indicate something happened on a specific date.

--
Paige Miller
kelxxx
Quartz | Level 8

Yes, I agree with you.
I need to import the data into a file.
There is a date field, and in this field there are year values < 1582.
Certainly, there are errors or incidents to report.
But I want to know if there is a solution to circumvent it.
Because this SAS error will block what I want to do next.

Kurt_Bremser
Super User

Are you really sure you have to deal with dates in the 3rd century AD? Or is this simply an error in the data caused by some kind of truncation?

If this are real dates, you need to dissect (SUBSTR) them upon reading and store them as separate day, month and year variables.

ballardw
Super User

@kelxxx wrote:

Yes, I agree with you.
I need to import the data into a file.
There is a date field, and in this field there are year values < 1582.
Certainly, there are errors or incidents to report.
But I want to know if there is a solution to circumvent it.
Because this SAS error will block what I want to do next.


One of the reasons that SAS only accepts date after 1582 is because calendars were not very standard. And subject to change frequently and by geography. A date of "1 March" in one country could be in February or days later in another.

 

If you actually have data that goes back that far I would parse your date to Day, Month and Year values.

If you are going to try to do any interval calculations good luck.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 907 views
  • 2 likes
  • 4 in conversation