DATA Step, Macro, Functions and more

date and time stamp on input file

Reply
Contributor
Posts: 20

date and time stamp on input file

I have a comma delimtier file and a field coming in at 6/1/2016 12:00:00 AM.  How do i read that in on my input step?  I just want the date of 6/1/2016

 

 

Thank you

Super User
Posts: 5,441

Re: date and time stamp on input file

Easiest is to read the whole datetime field first, and in a later step extract the date via the datepart function.
Data never sleeps
Super User
Super User
Posts: 7,997

Re: date and time stamp on input file

If you import the properly, with a datastep and infile, and you read that data as a date-time, then you already have the date.  You can extract it using the function datepart().  Thus is fouy want a character version you would just add:

char_date=put(datepart(dt_var),date9.);
Super User
Super User
Posts: 7,077

Re: date and time stamp on input file

If you use the ANYDTDTE. informat it will read it and store just the date part as a date value.

 

Or use the ANYDTDTM. informat and it will create a datetime value. You could then use DTDATE. formar to just display the date. or use the DATEPART() function to extract the date.

 

Super User
Posts: 11,343

Re: date and time stamp on input file

I'm with @Tom on this. I read lots of files with that date (almost time) field as dates because the data source exposes data as date and time but the time values are invariate (all 12:00:00 AM for example). Why anyone lets "time" become part of something when it never changes continues to annoy me greately.

Ask a Question
Discussion stats
  • 4 replies
  • 122 views
  • 3 likes
  • 5 in conversation