In my data, the date variables values contain the following values.
date1
12/May/2015
UN/UNK/2004
UN/Aug/2000
un/UNK/2001
10/UNK/2008
un/Mar/2003
un/UNK/un
output needed
2015-05-12
2004
2000-08
2001
2008--10
2003-03
blank
How to read the date1 values to get the output. Thanks Please help
How were the solutions provided two weeks ago to the same question inadequate?
Thanks for the hint @PGStats
I've already spent time for a solution to your question but I've now realized that you A) already asked this question before and B) don't give a lot of feedback and/or mark questions as answered.
So waiting until you've done your bit before posting anything.
I still remember there are many people have already answered your question. Wouldn't those code work for you ? data have; input date1 $20.; cards; 12/May/2015 UN/UNK/2004 UN/Aug/2000 un/UNK/2001 10/UNK/2008 un/Mar/2003 un/UNK/un ; run; proc format; invalue mon(upcase) 'JAN'=1 'FEB'=2 'MAR'=3 'APR'=4 'MAY'=5 'JUN'=6 'JUL'=7 'AUG'=8 'SEP'=9 'OCT'=10 'NOV'=11 'DEC'=12; run; data want; set have; length want $ 20; temp=prxchange('s/unk?//i',-1,date1); x=scan(temp,-1,'/','m'); want=catx('-',want,x); x=scan(temp,-2,'/','m'); want=catx('-',want,put(input(x,mon.),z2.)); x=scan(temp,-3,'/','m'); want=catx('-',want,x); want=translate(want,' ','.'); drop x temp; run;
Please don't post new questions to an old existing thread but open a new question and eventually reference the old discussion as a link.
To answer your question:
A date must be a specific day in the calendar and "unk" doesn't give you such information. For this reason you can't logically convert such a string to a date unless you make a business decision to what "unk" should translate (i.e. to January or to July....).
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.