DATA Step, Macro, Functions and more

How to read date values containing Unknown characters

Reply
Super Contributor
Posts: 270

How to read date values containing Unknown characters

[ Edited ]

 

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

 

 

Respected Advisor
Posts: 4,640

Re: hoe to read date values containing Unknown chracters

How were the solutions provided two weeks ago to the same question inadequate?

PG
Respected Advisor
Posts: 3,886

Re: hoe to read date values containing Unknown chracters

Thanks for the hint @PGStats

 

@knveraraju91

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.

Super User
Posts: 9,658

Re: hoe to read date values containing Unknown chracters

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;


Ask a Question
Discussion stats
  • 3 replies
  • 229 views
  • 0 likes
  • 4 in conversation