DATA Step, Macro, Functions and more

Problem with Dates

Reply
New Contributor
Posts: 2

Problem with Dates

Hi,

I am working on on SQL Server Database, with a low date as 0001-01-01, While reading this data into SAS these values are shown a nulls or ***** can any one of you please help on this. One millions thanks well in advance.

 

WIth regards

 

Ramana Potluri

Super User
Posts: 9,676

Re: Problem with Dates

***  usually because length of format is too short, try assign a longer format 
Like format date date9.

Or remove that format and see what is going on in it .
proc print ;
format date;


New Contributor
Posts: 2

Re: Problem with Dates

I have already tried this. This did not work.

My problem here any date prior to 1958-01-01 is reading as missing. How can I resolve this.

Super User
Posts: 9,676

Re: Problem with Dates

Maybe you could import these date into SAS as character (at SQL Server side)
and transform it into data by INPUT() .


Super User
Posts: 3,105

Re: Problem with Dates

What is the column type in SQL Server? Datetime or something else? How are you reading SQL Server? SAS/ACCESS to SQL Server or ODBC?

Super User
Posts: 6,936

Re: Problem with Dates


VRPotluri wrote:

I have already tried this. This did not work.

My problem here any date prior to 1958-01-01 is reading as missing. How can I resolve this.


That would be very strange, as SAS accepts dates back to the 16th century:

dateval = input(datestring,yymmdd10.);
format dateval yymmddd10.;
cards;
1960-01-01
1958-01-01
1850-01-01
1750-01-01
1690-01-01
1590-01-01
;
run;

proc print;
run;

Result:

Obs    datestring       dateval

 1     1960-01-01    1960-01-01
 2     1958-01-01    1958-01-01
 3     1850-01-01    1850-01-01
 4     1750-01-01    1750-01-01
 5     1690-01-01    1690-01-01
 6     1590-01-01    1590-01-01
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,497

Re: Problem with Dates

Since I doubt that you have any actual values recorded for 0001-01-01 I suspect that exact value is being used as either a place holder or indicator for missing or invalid data. Due to vagaries of history and inconsistent calendars SAS does not support dates prior to the English adoption of the Gregorian calendar.

 

Also if you are looking at OUTPUT in Excel by any chance, Excel doesn't support dates prior to 1900.

Ask a Question
Discussion stats
  • 6 replies
  • 308 views
  • 0 likes
  • 5 in conversation