Flagging low risk, date of birth changes

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 84
Accepted Solution

Flagging low risk, date of birth changes

hello,

 

I'm seeking guidance toward building  code that can modify aspects of a date, specifically the customer's date of birth (dob).The purpose  is to pinpoint potential fraud (as a dob typically never changes, unless due to data entry error, or fraud).

 

Example variables:   old_birthday: 01jan1980   | new_birthday: 03mar1982.  

 

Format of birthday is date9., using SAS 9.4. I need to flag those where the change in the dob is low risk, such as those meeting the two below conditions: 

 

From first variable (old_birthday): 

A-Reverse last two digit of year. Example: have 05jan1967 want 05jan1976 

B-Swap day with month. Example: have 05jan1980 want 01may1980 

 

If want=new_birthday then do;High_Risk=’N’;end;

 

Any suggestions are highly appreciated, thanks in advance,


Accepted Solutions
Solution
‎08-19-2016 04:17 PM
Respected Advisor
Posts: 4,651

Re: Flagging low risk, date of birth changes

Test against dateA and dateB given by:

 

data _null_;
do date = '05jan1967'd,'05jan1980'd;
    dateA = mdy(month(date), day(date), 
	   100*int(year(date)/100) + 10*mod(year(date), 10) + mod(int(year(date)/10), 10));
    dateB = mdy(day(date), month(date), year(date));
    put (date datea dateb) (=yymmdd10.);
    end;
run;
PG

View solution in original post


All Replies
Solution
‎08-19-2016 04:17 PM
Respected Advisor
Posts: 4,651

Re: Flagging low risk, date of birth changes

Test against dateA and dateB given by:

 

data _null_;
do date = '05jan1967'd,'05jan1980'd;
    dateA = mdy(month(date), day(date), 
	   100*int(year(date)/100) + 10*mod(year(date), 10) + mod(int(year(date)/10), 10));
    dateB = mdy(day(date), month(date), year(date));
    put (date datea dateb) (=yymmdd10.);
    end;
run;
PG
Respected Advisor
Posts: 3,124

Re: Flagging low risk, date of birth changes

Put it back to Char, then we are playing a Char game, this is just one of the possible solutions,

 

data have;
format old_dt new_dt date9.;
old_dt='05jan1969'd;new_dt='5jan1996'd;output;
old_dt='5jan1980'd;new_dt='1may1980'd;output;
run;

data want;
set have;
_old=put(old_dt,yymmdd8.);
_new=put(new_dt,yymmdd8.);
if _old ne _new then do;
if _new=prxchange('s/(^\d)(\d)/$2$1/oi',-1,_old) then flag_a=1;
if _new=prxchange('s/(-\d\d)(-\d\d$)/$2$1/oi',-1,_old) then flag_b=1;
end;
run;
Frequent Contributor
Posts: 84

Re: Flagging low risk, date of birth changes

very interesting! Could you help me add 3 more flags to your code? 

 

-if difference in old date and new date, is either -1, or 1 in either day month or year. Here's the code I had created:

 

dd=day(new_birthday)-day(old_birthday);
mm=month(new_birthday)-month(old_birthday);  
yy=year(new_birthday)-year(old_birthday);
if dd in (-1,1) then do; FLAG_D=1;END;
IF MM  in (-1,1) then do; FLAG_M=1;END;
IF YY in (-1,1) then do; FLAG_Y=1;END;

i'm fairly new to sas.. thank you

Occasional Contributor
Posts: 9

Re: Flagging low risk, date of birth changes

I think this code checks if the new and the old days, months and years are within 1 of each other.  ie. Its checking for a different kind of typo  than requested in the original post (ie. typing 7 when you meant 8) but still very relevant as it's likely to be low risk

Frequent Contributor
Posts: 84

Re: Flagging low risk, date of birth changes

correct, it will be included...

Respected Advisor
Posts: 4,651

Re: Flagging low risk, date of birth changes

If you are loking for typos, you could use the edit distance with a small cutoff value:

 

match = complev(put(date1, yymmdd10.), put(date2, yymmdd10.), 1) <= 1;

 

Look at the description of the complev distance function in the documentation. 

PG
Frequent Contributor
Posts: 84

Re: Flagging low risk, date of birth changes

Thanks for your help and for this tip ... I will research the complev function
Occasional Contributor
Posts: 9

Re: Flagging low risk, date of birth changes

*set everything that has different birthdays as high risk;

if old_birthday -new_birthday>0 then flag="highrisk";

  else flag="lowrisk";

 

*set those with reversed day months back to low risk;

if (month(new_birthday)=day(old_birthday) or day(new_birthday)=month(old_birthday) then flag="lowrisk";

 

*separate out the last and second last digits in year;

yearold=year(old_birthday);

yearnew=year(new_birthday);

yearlastdigitnew= yearnew-int(yearnew/10)*10;

yearlastdigitold=yearold-int(yearold/10)*10;

year2ndlastdigitnew=int(yearnew/10)-int(yearnew/100)*10;

year2ndlastdigitold=int(yearold/10)-int(yearold/100)*10;

 

*set those with reverse last year digits to low risk;

if (yearlastdigitnew=year2ndlastdigitold) or (yearlastdigitold=year2ndlastdigitnew) then flag="lowrisk";

Frequent Contributor
Posts: 84

Re: Flagging low risk, date of birth changes

thanks Avery, your solution works as well ... appreciate the explanations offered.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 430 views
  • 4 likes
  • 4 in conversation