BookmarkSubscribeRSS Feed
FloydNevseta
Pyrite | Level 9

I receive a text file that has timestamps formatted as yyyymmdd:hh:mm:ss. Initially, I thought that the ANYDTDTM. informat would be a perfect choice for reading this data into a SAS datetime value. However, I see some inconsistency with how SAS converts the text into a datetime. Specifically, the inconsistency is with how the date part of the text is interpreted. Consider the following data step. The expected dates are 05Nov2011 and 05Jan2011. The first date is correct, but the 2nd date of 01Nov1920 is certainly wrong. It's as if the first 6 characters (201101) were used to determine the date. But if that were the case, then the first date could be interpreted as 11Nov2011. Can anyone explain this inconsistency?

To add to the confusion, I asked colleagues on my team to run the same datastep and share their results. One of my teammates got the exact opposite outcome. The date of the first obs was 11Nov2011 and the date of the 2nd obs was 05Jan2011.

data test;
infile cards;
input dtm anydtdtm19.;
format dtm datetime19.;
cards;
20111105:20:31:55
20110105:20:31:55
;
run;

proc print;
run;

Results:

Obs                    dtm

1      05NOV2011:20:31:55
2      01NOV1920:20:31:55

6 REPLIES 6
art297
Opal | Level 21

I would raise this one with tech support.  In the meantime, doing a bit or pre-processing at least will get you the correct dates.  E.g.:

options datestyle=ymd;

data test (drop=_:);

  infile cards;

  input _dtm $17.;

  format dtm datetime19.;

  dtm=input(catt(substr(_dtm,1,4),

         '-',substr(_dtm,5,2),

         '-',substr(_dtm,7,2),

         substr(_dtm,9)),YMDDTTM24.);

cards;

20111105:20:31:55

20110105:20:31:55

;

run;

art297
Opal | Level 21

or, a slightly cleaner possible way of accomplishing the desired result:

data test;

  infile cards;

  informat dtm B8601DT17.;

  input @;

  substr(_infile_,find(_infile_,':'),1)='T';

  input dtm;

  format dtm datetime19.;

cards;

20111105:20:31:55

20110105:20:31:55

;

run;

Ksharp
Super User

But I tested it. No problem.

Maybe you need to talk to Technical Support.

Ksharp

LarryWorley
Fluorite | Level 6

I tried and got the same error with 9.2.3 on windows with yearcutoff = 1920.  When I changed yearcutoff to 1950, I get different error but from the same input value.  Get 01NOV2020:20:31:55.

Please talk to tech support.

FriedEgg
SAS Employee

I believe this issue is related to the fact that ynddttm informat REQUIRES separators between the year, month, and date fields as well at the time fields.  Unlike the similar formats mdyampm and datetime where the separators are optional.

data _null_;

input @;

  _infile_=prxchange('s/(\d{4})(\d{2})(\d{2})(.*)/\1-\2-\3\4/o',1,_infile_);

  put _infile_;

input dtm ymddttm24.;

put dtm datetime19.;

cards;

20111105:20:31:55

20110105:20:41:55

;

run;

2011-11-05:20:31:55                                                            

05NOV2011:20:31:55

2011-01-05:20:41:55                                                            

05JAN2011:20:41:55

options datestyle=ymd;

data _null_;

input @;

  _infile_=prxchange('s/(\d{4})(\d{2})(\d{2})(.*)/\1-\2-\3\4/o',1,_infile_);

  put _infile_;

input dtm anydtdtm24.;

put dtm datetime19.;

cards;

20111105:20:31:55

20110105:20:41:55

;

run;

2011-11-05:20:31:55                                                            

05NOV2011:20:31:55

2011-01-05:20:41:55                                                            

05JAN2011:20:41:55

FloydNevseta
Pyrite | Level 9

I eventually reported this issue to tech support. They acknowledged the defect and created the following SAS Note.

http://support.sas.com/kb/46/142.html

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 3881 views
  • 1 like
  • 5 in conversation