Parsing date from FileName

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

Parsing date from FileName

Hello everyone,

I'm looking for the best approach of parsing JUL0414 from a file into a date format of 2014-07-04.

Any suggestions.

Regards,

Jonathan


Accepted Solutions
Solution
‎07-16-2014 09:15 PM
Super User
Super User
Posts: 6,499

Re: Parsing date from FileName

%let filename=JUL0414.txt ;

%let date=%sysfunc(inputn(%substr(&filename,4,2)%substr(&filename,1,3)%substr(&filename,6,2),date7.),yymmdd10.);

View solution in original post


All Replies
Super User
Posts: 17,794

Re: Parsing date from FileName

Is this a variable in a table in character form?

Valued Guide
Posts: 2,174

Re: Parsing date from FileName

Assuming  a datastep variable datestring holding JUL0414

Datevar = input( substr( datestring, 4,2)!! substring( datestring, 1,3)!! substr( datestring,6,2), date7. ) ;

Contributor
Posts: 70

Re: Parsing date from FileName

The source file name is a brought in as a macro variable.

Looking to take the first seven characters and parse them into a date.

Solution
‎07-16-2014 09:15 PM
Super User
Super User
Posts: 6,499

Re: Parsing date from FileName

%let filename=JUL0414.txt ;

%let date=%sysfunc(inputn(%substr(&filename,4,2)%substr(&filename,1,3)%substr(&filename,6,2),date7.),yymmdd10.);

Contributor
Posts: 70

Re: Parsing date from FileName

Tom,

Thank you so much this is perfect

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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