Hello everybody!
I have to randomized the subjects for an Experiment and assigned them to a "Treatment" Group or a "Placebo" Group.
I would like to write a programm with SAS that find the best matches in a list of subjects and matches them based on different Parameters (such as Age and Sex).
For example having one dataset that Looks as follow:
ID Sex Age
01 M 23
02 M 37
03 F 29
04 M 25
05 F 30
....
The Programm should give me back as result that the best matches are:
Subj 01 -> Subj 04 (Sex M=M; Age 23=25)
Subj 03 -> Subj 05 (Sex F=F; Age 29=30)
and so on....
I looked in the Internet but I can´t find any tutorial about it. Can someone help me posting the link of a source where I can learn to do this or give me some tipps?
Thank you!
data have;
input ID Sex $ Age ;
cards;
01 M 23
02 M 37
03 F 29
04 M 25
05 F 30
;
run;
proc sql;
select a.*,b.id as _id
from have as a,have as b
where a.id ne b.id and a.sex=b.sex
group by a.id
having abs(a.age-b.age) = min(abs(a.age-b.age));
quit;
data have;
input ID Sex $ Age ;
cards;
01 M 23
02 M 37
03 F 29
04 M 25
05 F 30
;
run;
proc sql;
select a.*,b.id as _id
from have as a,have as b
where a.id ne b.id and a.sex=b.sex
group by a.id
having abs(a.age-b.age) = min(abs(a.age-b.age));
quit;
Try the PSMATCH procedure documentation: https://support.sas.com/documentation/onlinedoc/stat/142/psmatch.pdf
One spot (of many) to look at specifically is Example 95.6: Mahalanobis Distance Matching. In the output statement of PSMATCH, include the MATCHID=_MatchID option to create a variable named _MatchID that identifies the matched sets of observations.
You'll need to include the column that designates each subject as either "test" or "control".
Works perfect! Thank you very much!!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.