Quartz | Level 8

## How to read a 3 digit year? Invalid date/time/datetime constant

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

## Re: How to read a 3 digit year? Invalid date/time/datetime constant

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
6 REPLIES 6
Diamond | Level 26

## Re: How to read a 3 digit year? Invalid date/time/datetime constant

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
Quartz | Level 8

## Re: How to read a 3 digit year? Invalid date/time/datetime constant

``````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.

Diamond | Level 26

## Re: How to read a 3 digit year? Invalid date/time/datetime constant

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
Quartz | Level 8

## Re: How to read a 3 digit year? Invalid date/time/datetime constant

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.

Super User

## Re: How to read a 3 digit year? Invalid date/time/datetime constant

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.

Super User

## Re: How to read a 3 digit year? Invalid date/time/datetime constant

@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.

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