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-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
  • 4 replies
  • 1651 views
  • 3 likes
  • 5 in conversation