@PRoul
I see two issues with your solution:
You are not solving the problem as stated by the OP. You are doing EXACT matches of AGE between case and control. But the OP was requesting matches having case_age within a range of case_control. Assuming the OP would be equally satisfied with a "close" match vs an "exact" match, this program may not fully satisfy the initial request. Of course, the OP might prefer to exclude close matches.
More importantly, your solution is unlikely to generate anything like a random sample of matches (unlike PSMATCH). In particular, records near the end of the control dataset will not have the same probability of being selected as records near the start, even though they have the same match values. That is because.
PROC SORT, by default, does not change the order of records having identical sort keys.
hash objects using the multidata:'Y' option preserves the order of data items having the same key to match the order retrieved from the source dataset. This means your technique of FIND method followed by a series of FINDNEXT methods will always result in the data items near the start of the of the dataset being the first ones considered. This is true even though you are sampling without replacement.
Now if your control dataset is in truly random order to begin with (i.e. before the proc sort), you would effectively have a random solution. But with real datasets, it's pretty heroic to assume they are in random order.
You could resolve this problem by randomizing the order of data within each match key as follows:
data controls;
set controls;
matchkey = catx('_', gender_control , age_control);
call streaminit(0598666);
rnum=rand('uniform');
run;
proc sort data = controls out=controls;
by matchkey rnum;
run;
followed by your data step with hash code.
This would effectively mean that every observation with a given matchkey value would have the same probability of being selected.
BTW, for purposes of matching cases and controls, there is no need to sort the CASES file. It's just wasted resources.
... View more