BookmarkSubscribeRSS Feed
myboys2
Fluorite | Level 6

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

4 REPLIES 4
LinusH
Tourmaline | Level 20
Easiest is to read the whole datetime field first, and in a later step extract the date via the datepart function.
Data never sleeps
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.);
Tom
Super User Tom
Super User

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.

 

ballardw
Super User

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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2705 views
  • 3 likes
  • 5 in conversation