Problems with matched sampling using SAS

#1
Hi,

I tried to find matched control matches to multiple variables:
1) age +/- 10 years and
2) diabetes

I used the codes as shown below (Ref:http://www.lexjansen.com/pharmasug/2000/Posters/p07.pdf.
However, in matched control only diabetes=NO were selected. At first I thought maybe due to insufficient control. Thus, I tried and changed the ratio to 1:1 and 1:2. But the results still the same.
How can I fix this problem?

Thank you.


Code:
%LET AGERANGE = 10;
%LET RATIO = 4;
DATA CASES CONTROLS;
SET All;
IF EVENT = 0 THEN OUTPUT CASES;
ELSE OUTPUT CONTROLS;
PROC FREQ NOPRINT DATA=CASES;
TABLES AGE*DIABETES/OUT=CASEOUT;

%MACRO SAMPLE 
(V_AGE,V_DIABETES,V_COUNT);
DATA QUALIFY1; SET CONTROLS;
WHERE (&V_AGE-&AGERANGE
<=AGE<=&V_AGE+&AGERANGE)
AND (DIABETES = "&V_DIABETES");

CASES_AGE=&V_AGE;
CASES_DIABETES="&V_DIABETES";

SEED=RANUNI(0);
PROC SORT; BY SEED;

DATA QUALIFY2;
SET QUALIFY1 NOBS=TOTOBS;
IF _N_<=&V_COUNT*&RATIO;
IF &V_COUNT*&RATIO <= TOTOBS THEN TAG = 'YES';
ELSE TAG = 'NO';

PROC APPEND BASE=MATCHES DATA=QUALIFY2;

PROC SORT DATA=QUALIFY2 OUT=TEMP1
(KEEP=NUMBER); BY NUMBER;

PROC SORT DATA=CONTROLS OUT=TEMP2;
BY NUMBER;

DATA CONTROLS;
MERGE TEMP1(IN=IN1) TEMP2(IN=IN2);
BY NUMBER; IF IN2 AND NOT IN1;

%MEND SAMPLE;
 
#2
Hi,

I think the problems has settled by correcting the variable coding. I have found matched control (1:4) who met the matching criteria i.e age +/- 10 years and diabetes variables with the cases.

The correction codes as below:

Code:
%LET AGERANGE = 10;
%LET RATIO = 4;
DATA CASES CONTROLS;
SET All;
IF EVENT = 0 THEN OUTPUT CASES;
ELSE OUTPUT CONTROLS;
PROC FREQ NOPRINT DATA=CASES;
TABLES AGE*DIABETES/OUT=CASEOUT;

%MACRO SAMPLE 
(V_AGE,V_RESPONSE,V_COUNT);
DATA QUALIFY1; SET CONTROLS;
WHERE (&V_AGE-&AGERANGE
<=AGE<=&V_AGE+&AGERANGE)
AND (DIABETES = "&V_RESPONSE");

CASES_AGE=&V_AGE;
CASES_DIABETES="&V_DIABETES";

SEED=RANUNI(0);
PROC SORT; BY SEED;

DATA QUALIFY2;
SET QUALIFY1 NOBS=TOTOBS;
IF _N_<=&V_COUNT*&RATIO;
IF &V_COUNT*&RATIO <= TOTOBS THEN TAG = 'YES';
ELSE TAG = 'NO';

PROC APPEND BASE=MATCHES DATA=QUALIFY2;

PROC SORT DATA=QUALIFY2 OUT=TEMP1
(KEEP=NUMBER); BY NUMBER;

PROC SORT DATA=CONTROLS OUT=TEMP2;
BY NUMBER;

DATA CONTROLS;
MERGE TEMP1(IN=IN1) TEMP2(IN=IN2);
BY NUMBER; IF IN2 AND NOT IN1;

%MEND SAMPLE;