If data contains UN----it should replace with -----01
if data contains UNK------it should replace with -----jan
if data contains UN-UNK-UNKY------ it should be missing....
data have;
input dt $15.;
cards;
23-jan-2000
un-feb-2001
un-unk-2002
un-unk-unky
un-may-1999
un-mar-2002
un-unk-2010
run;
Required Output:
23-jan-2000
01-feb-2001
01-jan-2002
01-may-1999
01-mar-2002
01-jan-2010
As UNKY contains UNK and the last contains UN,
I shall check from the longest to the shortest string:
data want;
set have;
dt = upcase(dt); /* line added */
i = index(dt,'UNKY');
if i > 0 then dt= ' '; /* line was edited as dt is char type */
else do;
i = index(dt,'UNK');
if i>0 then substr(dt,4,3) = 'jan';
else do;
i = index(dt,'UN');
if i = 1 then substr(dt,1,2) = '01';
end; end;
run;
sorry it not working any other way just I ran in sas i'm getting exact what I said... Thanks for reply...
Have you matched case writting:
If UN-UNK-UNKY in input are all lowcase check for un-unk-unky
or you can precede a line with dt=upcase(dt); before checking for UN-UNK-UNKY (in upper case letters).
Alternatively you can do:
data want;
set have;
if substr(dt,1,2) = 'un' then
substr(dt,1,2) = '01';
if substr(dt,4,3) = 'unk' then
substr(dt,4,3) = 'jan';
if substr(dt,8.4) = 'unky' then dt = ' ';
run;
data have; input dt $15.; dt=prxchange('s/\bun\b/01/',1,dt); dt=prxchange('s/\bunk\b/jan/',1,dt); want=input(dt,?? date11.); format want date11.; cards; 23-jan-2000 un-feb-2001 un-unk-2002 un-unk-unky un-may-1999 un-mar-2002 un-unk-2010 ; run;
Sorry . I have no time to explain PRXCHANGE(), search it at support.sas.com Here '\b' stand for the boundary of a word.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.