BookmarkSubscribeRSS Feed
sunilreddy
Fluorite | Level 6

 

I've a raw file with different date values in different records.

 

eX:

 

Datalines;

08DEC2015

12112014

201113

 

;

 

How to read different date types from raw file.

4 REPLIES 4
Reeza
Super User
You can try ANYDTDTE or you can bring it in as character and then try and parse it out using some logic if/then statements.


data want;
format date date9.;
input date anydtdte.;
cards;
08DEC2015
12112014
201113
;
run;

proc print data=want;
run;
ballardw
Super User

Don't be surprised if you get values you don't expect.

Your example of 12112014 will depend on your national language setting for whether that is supposed to be MM/DD/YY or DD/MM/YY.

And 201113 is likely to have problems if it is supposed to be YYYYMMDD as it could be interpreted as 2011 Jan 3 or 20 Nov 2013

Reeza
Super User
Here's an example of a thorough process...it's a bit of work. I've seen some cleaner regex solutions, but I can't seem to find any right now.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Personally I wouldn't risk trying to work with that data.  Go back to your data import agreement - you have on of those right? - and check what it states in there.  If you dont have one of those, make one and get the vendor to agree to it.  They should be providing a robust, structured dataset, which they currently are not.  For instance, what does 12112014, mean?  Is it december or november.  As with everything programmatic - specify, specify, specify, then code.  Programming is in fact 99% irrelevant, specification and documentation is the key.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1181 views
  • 0 likes
  • 4 in conversation