DATA Step, Macro, Functions and more

Reading dates that are not complete and contain irrelevant letters

Reply
Super Contributor
Posts: 272

Reading dates that are not complete and contain irrelevant letters

Dear,

 

In my data, the date variable has values 16/Oct/2015 and un/Jan/2016.

 

I am using the code to convert to IS8601 dates.

code:

date1=input(date,date11.);
isdate=put(date1,is8601da.);

 

This code is not converting the "un/Jan/2016". What should I include in my code. I need value '2016-01' for '"un/Jan/2016".'  Please help. Thanks.

SAS Super FREQ
Posts: 8,862

Re: Reading dates that are not complete and contain irrelevant letters

Posted in reply to knveraraju91
Hi:
What is the 'un'? Is it a code that stands for "unknown" or is it the word for a number un=uno?

In either case, assuming that date is a character variable and that you need to substitute a day value for the 'un' for the INPUT to work correctly, you have to pick a day value to substitute for the 'un' - I generally choose 01, but you could choose 15 or 30 or any other number.

I would suggest a simple IF statement (not tested):
if index(date,'un') > 0 then do;
date1 = input(catt('01'||substr(date,3)),date11.);
end;
else date1=input(date,date11.);

cynthia
Ask a Question
Discussion stats
  • 1 reply
  • 173 views
  • 1 like
  • 2 in conversation