data dup;
length key date1 date2 8;
input key date1 date2 ;
datalines;
1 0 3
1 4 7
2 1 2
3 3 4
3 7 9
3 10 11
;
proc print;run;
data test;
do i=1 to 20;
key=ceil(5*ranuni(123));
purchase_date=ceil(10*ranuni(123));
output;
end;
run;
proc print;run;
data test2;
if _N_=1 then do;
dcl hash h(dataset:'dup', multidata: 'y');
h.definekey('key');
h.definedata('key', 'date1', 'date2');
h.definedone();
end;
/* avoid uninitialized variable notes */
call missing (key, date1, date2 );
set test;
rc = h.find();
find=0;
if (rc = 0) then do;
if date1<=purchase_date<=date2 then do;
key2=catx('#',key, put(date1,date9.), put(date2,date9.));
output;
find=1;
end;
rc = h.find_next();
do while(rc = 0);
if find=1 then leave;
if date1<=purchase_date<=date1 then do;
key2=catx('#',key, put(date1,date9.), put(date2,date9.));
find=1;
output;
end;
rc = h.find_next();
end;
if find=0 then do;
remark='out of date range';
output;
end;
end;
else do;
key2='ERROR';
output ;
end;
run;
proc print;run;