BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

 

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

 

 

5 REPLIES 5
PGStats
Opal | Level 21

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

PG
Patrick
Opal | Level 21

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.

Ksharp
Super User
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;


Sritheja
Calcite | Level 5
How to convert unk from 01/unk/1976 in date format
Patrick
Opal | Level 21

@Sritheja 

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....).

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3326 views
  • 0 likes
  • 5 in conversation