BookmarkSubscribeRSS Feed
molla
Fluorite | Level 6

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

 

2 REPLIES 2
art297
Opal | Level 21

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

 

Tom
Super User Tom
Super User

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;

 

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
  • 2 replies
  • 632 views
  • 0 likes
  • 3 in conversation