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

Hello Team , 

 

The DB2 table had the value '0001-01-01 00:00:00.000000' in Trans_time column  as a default time .

But while reading and loading to a sas data set , this value is converted as null  . am using datetime26.6 while defining the column in DIS

learn_SAS_23_0-1661519501332.png

 

it works for all other rows  ex : 2022-06-30 04:37:21.973671 , but only the row which has '0001-01-01 00:00:00.000000' is converted in to NULL

Can some one guide , how to convert ''0001-01-01 00:00:00.000000'' value from db2 to sas 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Years prior to about 1582 are not valid years because of calendar inconsistencies prior.

I doubt that your data is actually from Year 1 CE(and you really have to be specific about where you are to get January 1 as the calendar has been played with a lot since anything resembling Year 1 CE.

 

SAS will treat any attempt to use a year prior to 1582 as invalid hence the missing value. I bet that you log shows an "invalid data" message somewhere.

View solution in original post

6 REPLIES 6
AMSAS
SAS Super FREQ

The question is what does that date represent, I'm assuming it's not midnight on the 1st January 0001, and SAS is probably assuming it's an invalid date thus setting it to missing.

learn_SAS_23
Quartz | Level 8
its a default date in our source system , we are just want to maintain same source data in sas datasets
FreelanceReinh
Jade | Level 19

Hello @learn_SAS_23,

 

You could define a custom informat and format. As there is no numeric equivalent in SAS for the datetime "0001-01...", I suggest a special missing value, e.g., .D.

proc format;
invalue DB2dt
'0001-01-01 00:00:00.000000' = .d
other = [e8601dt26.];

value DB2dt
.d = '0001-01-01T00:00:00.000000'
other = [e8601dt26.6];
run;

I'm not familiar with DB2 or DIS, so the example below uses SAS character data.

/* Create example data for demonstration */

data have;
input Trans_time $26.;
cards;
2022-06-30 04:37:21.973671
0001-01-01 00:00:00.000000
;

/* Convert DB2 to SAS datetime values */

data want;
set have;
Trans_dt=input(Trans_time, DB2dt.);
format Trans_dt DB2dt.;
run;

proc print data=want;
run;

Output:

Obs            Trans_time                     Trans_dt

 1     2022-06-30 04:37:21.973671    2022-06-30T04:37:21.973671
 2     0001-01-01 00:00:00.000000    0001-01-01T00:00:00.000000
ballardw
Super User

Years prior to about 1582 are not valid years because of calendar inconsistencies prior.

I doubt that your data is actually from Year 1 CE(and you really have to be specific about where you are to get January 1 as the calendar has been played with a lot since anything resembling Year 1 CE.

 

SAS will treat any attempt to use a year prior to 1582 as invalid hence the missing value. I bet that you log shows an "invalid data" message somewhere.

learn_SAS_23
Quartz | Level 8
thanks for everyone inputs , from this Atleast DIS doesn't support the dates prior to about 1582 , all are treated as NULL
Tom
Super User Tom
Super User

You don't need that in SAS.  Unlike DB2 in SAS boolean logic is actually boolean, there are only two outcomes, TRUE or FALSE.

In DB2 comparisons using a null value (what SAS would call a missing value)  result in a null result instead of either TRUE or FALSE.  Since SAS treats missing as less than any actual number the result will be the same as you get in DB2 by using that ridiculous value.

 

I am not totally sure how "default" values work in DB2 , but that might also make the missing values in the SAS datasets work when trying to insert observations back into the DB2 table.  The missing values might be converted to DB2 null values and thus trigger DB2 to store instead the default value.  Try it and see.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 5329 views
  • 2 likes
  • 5 in conversation