BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aexor
Lapis Lazuli | Level 10

There is a column of DATE with diff formats, I want to write a dynamic code that can read all these dates:
DATE
20112017 (DDMMYYYY)
21072017 (DDMMYYYY)
09212017 (MMDDYYYY)
01JAN2017 (DDMONYYYY)

 

Please help.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input DATE : $20. format : $20. ;
want=inputn(date,format);
format want date9.;
cards;
20112017 DDMMYY10.
21072017 DDMMYY10.
09212017 MMDDYY10.
01JAN2017 DATE9. 
;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

If some of the dates have month before day, and other dates have day before month, then you are in a situation where no global answer exists. Although 20112017 must be day 20 of month 11 (because it can't be day 11 of month 20), there is no way for anyone to know which is the day and which is the month if your input data 04112017.

 

So, you have to make a decision about how these inputs should be handled. This really isn't a SAS question any more, this is a question for you to decide.

--
Paige Miller
ballardw
Super User

Try the ANYDTDTE. informat.

Then look at results very closely because it is very likely to make assumptions, the similar to the way you would looking at some of those values.

I hope you don't have any 6-digit versions as with inconsistent layouts you cannot tell what 010203 would actually represent.

Ksharp
Super User
data have;
input DATE : $20. format : $20. ;
want=inputn(date,format);
format want date9.;
cards;
20112017 DDMMYY10.
21072017 DDMMYY10.
09212017 MMDDYY10.
01JAN2017 DATE9. 
;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 456 views
  • 3 likes
  • 4 in conversation