Hello, I have some data and need to compare with the other variable. If my data has full date (day month and year), I need to compare with day, month, and year. If my data has partial date (month and year only), I need to compare only month and year. If my data has partial date (year only), I need to compare only year. I create new_date variable in below code which is working as expected. I need to compare new_date with date2 variable as describe above. When I use for smaller dataset, it is working. When I am using with bigger dataset, I am getting a warning message for Month and Year date. NOTE: Invalid argument to function INPUT at line 87 column 7. data have;
input date1 $11. date2 $10.;
datalines;
UN UNK 2020 01MAY2020
UN UNK 2019 15MAY2018
UN JAN 2019 08JAN2020
01 JAN 2017 24JUN2018
7 SEP 2021 11DEC2021
UN UNK 0000 12DEC2021
;
run;
data want;
set have;
new_date = compress(prxchange('s/^UN|^00|^UK|^UNK|0000 //i',-1,date1));
*full date;
if length(new_date)>=8 then do;
base=input(strip(NEW_date),date9.);
compare=input(strip(substr(date2,1)),date9.);
format base compare date9.;
end;
*missing day (month and year);
if length(NEW_date)=7 then do;
base=input(strip(NEW_date),monyy7.);
compare=input(strip(substr(date2,3)),monyy7.);
format base compare monyy7.;
end;
*missing day and month (year);
if length(NEW_date)=4 then do;
base=input(strip(NEW_date),best.);
compare=input(strip(substr(date2,6)),best.);
format base compare best.;
end;
flag=(base<=compare);
*if flag = 1 then output;
run;
... View more