DATA Step, Macro, Functions and more

date time format

Reply
Contributor
Posts: 63

date time format

Please help me out inth following scenario.

 

 How to give informat for the below dates?

 

02-04-2017T22:12:35

02-10-2017T10:15:00

02-10-2017T10:15

 

PROC Star
Posts: 7,356

Re: date time format

[ Edited ]

There may be a more direct route, but the following should work:

 

data have;
infile cards truncover;
input @;
_infile_=catx(':',substr(_infile_,1,10),substr(_infile_,12));
input dt anydtdtm.;
format dt datetime19.;
cards;
02-04-2017T22:12:35
02-10-2017T10:15:00
02-10-2017T10:15
;

Art, CEO, AnalystFinder.com

 

Super User
Super User
Posts: 6,498

Re: date time format

I think you need to manipulate that to read it directly.

If you had the date part in the year,month,day order then you could use the B8601DT informat.

If you convert the T to a : then the ANYDTDTM informat could make a guess at what date to use.

If you know whether those dates are both in February or if one is in April and the other in October then you could read it in pieces using the appropriate informat. Or you could let SAS guess as to which informat to use by using the ANYDTDTE informat.

 

data have ;
  input @1 str $19.
        @1 dt1 anydtdtm19. 
        @1 d1 mmddyy10. +1 time time8. 
        @1 d2 ddmmyy10.
        @1 d3 anydtdte10.
  ;
  dt2 = input(translate(str,':','T'),anydtdtm19.);
  format dt1 dt2 e8601dt. d1 d2 d3 e8601da. time time8. ;
cards;
02-04-2017T22:12:35
02-10-2017T10:15:00
02-10-2017T10:15
;
proc print; run;

 

Ask a Question
Discussion stats
  • 2 replies
  • 132 views
  • 0 likes
  • 3 in conversation