Dear, In my data the following date values are present. The code below worked fine for all OBS containing similar values except for second OBS. The output for the first OBS I am getting 0000 and for the second OBS it is blank. For the third one i am getting 2000. Please help in my code to read when year =1960. Thank you. data1 OBS have_str 1 UN/UNK/0000 2 UN/UNK/1960 3 UN/UNK/2000 code: options missing=' ';
data want;
set have;
length want_str $11.;
/* valid day, month and year? */
want_str=put(input(have_str, ?? date11.),yymmdd10.);
if missing(want_str) and not missing(have_str) then
do;
length _day _month _year 8;
_day =input(scan(have_str,1,'/','m'), ?? best32.);
_month=month(input(scan(have_str,2,'/','m')||'2000', ?? monyy.));
_year =input(scan(have_str,3,'/','m'),?? best32.);
if _day<1 or _day>31 then call missing(_day);
if _month<1 or _month>12 then call missing(_month);
/* valid day and year? */
if mdy(01,_day,_year) then want_str=put(_year,z4.)||'--'||put(_day,z2.);
/* valid month and year? */
else if mdy(_month,01,_year) then want_str=put(_year,z4.)||'-'||put(_month,z2.);
/* valid year? */
else if mdy(01,01,_year) then want_str=put(_year,z4.);
end;
run; OUTPUT getting: data2 OBS want_str 1 0000 2 blank 3 2000 output need: OBS want_str 1 blank 2 1960 3 2000
... View more