Hi all,
I am new to sas and therefore new to %MACRO.
I am invoking a PSMatching MACRO and the code runs without any errors. However, I cannot locate the output.
Here is an example:
I am using SAS UE in a MAC. I checked and the version has MACRO enabled with :
PROC OPTIONS OPTION = MACRO;
run;
I would appreciate some help.
Thanks,
J
Okay, I see the problem, which I should have seen in your first post.
You have simply defined an empty macro that has no code. Furthermore, you never actually run the macro, and so nothing happens, and nothing would happen because it is an empty macro anyway.
Perhaps you have made a mistake somewhere, you need to define the macro, or include macro PSMATCHING, which you haven't done (and you can't skip this step, nothing will work if you don't define the macro or include it), and then you should run this line of code:
%PSMatching(datatreatment= _MIPD_Yes, datacontrol= _MIPD_No, method=NN, numberofcontrols= 3,
caliper=0.2, replacement= no, out= matches)
Add
options mprint;
to the top of your code, and run it again. If the results are not obvious after this, then show us the new SAS log.
Thanks for your input.
Unfortunately I still cannot see the output.
LOG:
Okay, I see the problem, which I should have seen in your first post.
You have simply defined an empty macro that has no code. Furthermore, you never actually run the macro, and so nothing happens, and nothing would happen because it is an empty macro anyway.
Perhaps you have made a mistake somewhere, you need to define the macro, or include macro PSMATCHING, which you haven't done (and you can't skip this step, nothing will work if you don't define the macro or include it), and then you should run this line of code:
%PSMatching(datatreatment= _MIPD_Yes, datacontrol= _MIPD_No, method=NN, numberofcontrols= 3,
caliper=0.2, replacement= no, out= matches)
I see this macro is available in this Gobal Forum paper: http://www2.sas.com/proceedings/forum2007/185-2007.pdf
The paper includes example code for running the macro (you were defining it not running it). To correctly run the macro:
data Treatment;
input pscoreT idT ageT group;
datalines;
0.10 1 25 1
0.20 2 22 1
;
data Control;
input pscoreC idC ageC group;
datalines;
0.07 3 45 0
0.08 4 37 0
0.11 5 20 0
0.45 6 27 0
0.47 7 47 0
;
run;
%PSMatching(datatreatment= Treatment, datacontrol= Control, method= NN
, numberofcontrols= 2, caliper=, replacement=no);
Thank you so much! It is running now without issues!
One question:
PRE-Matching
My treatment cohort is 427 and the control 4079
POST-Matching
My treatment cohort is 1281 and the control 1281
I am wanting to do a 3:1 match, and not sure why I ended up with the last numbers.
This is the MACRO I am using by Marcelo Coca Perraillon Paper 185-2007
%macro PSMatching(datatreatment=, datacontrol=,
method=, numberofcontrols=, caliper=,
replacement=, out=);
/* Create copies of the treated units if N > 1 */;
data _Treatment0(drop= i);
set &datatreatment;
do i= 1 to &numberofcontrols;
RandomNumber= ranuni(12345);
output;
end;
run;
/* Randomly sort both datasets */
proc sort data= _Treatment0 out= _Treatment(drop= RandomNumber);
by RandomNumber;
run;
data _Control0;
set &datacontrol;
RandomNumber= ranuni(45678);
run;
proc sort data= _Control0 out= _Control(drop= RandomNumber);
by RandomNumber;
run;
data Matched(keep = IdSelectedControl PScoreControl MatchedToTreatID PScoreTreat);
length pscoreC 8;
length idC 8;
/* Load Control dataset into the hash object */
if _N_= 1 then do;
declare hash h(dataset: "_Control", ordered: 'no');
declare hiter iter('h');
h.defineKey('idC');
h.defineData('pscoreC', 'idC');
h.defineDone();
call missing(idC, pscoreC);
end;
/* Open the treatment */
set _Treatment;
%if %upcase(&method) ~= RADIUS %then %do;
retain BestDistance 99;
%end;
/* Iterate over the hash */
rc= iter.first();
if (rc=0) then BestDistance= 99;
do while (rc = 0);
/* Caliper */
%if %upcase(&method) = CALIPER %then %do;
if (pscoreT - &caliper) <= pscoreC <= (pscoreT + &caliper) then do;
ScoreDistance = abs(pscoreT - pscoreC);
if ScoreDistance < BestDistance then do;
BestDistance = ScoreDistance;
IdSelectedControl = idC;
PScoreControl = pscoreC;
MatchedToTreatID = idT;
PScoreTreat = pscoreT;
end;
end;
%end;
/* NN */
%if %upcase(&method) = NN %then %do;
ScoreDistance = abs(pscoreT - pscoreC);
if ScoreDistance < BestDistance then do;
BestDistance = ScoreDistance;
IdSelectedControl = idC;
PScoreControl = pscoreC;
MatchedToTreatID = idT;
PScoreTreat = pscoreT;
end;
%end;
%if %upcase(&method) = NN or %upcase(&method) = CALIPER %then %do;
rc = iter.next();
/* Output the best control and remove it */
if (rc ~= 0) and BestDistance ~=99 then do;
output;
%if %upcase(&replacement) = NO %then %do;
rc1 = h.remove(key: IdSelectedControl);
%end;
end;
%end;
/* Radius */
%if %upcase(&method) = RADIUS %then %do;
if (pscoreT - &caliper) <= pscoreC <= (pscoreT + &caliper) then do;
IdSelectedControl = idC;
PScoreControl = pscoreC;
MatchedToTreatID = idT;
PScoreTreat = pscoreT;
output;
end;
rc = iter.next();
%end;
end;
run;
/* Delete temporary tables. Quote for debugging */
proc datasets;
delete _:(gennum=all);
run;
data &out;
set Matched;
run;
%mend PSMatching;
And I am invoking it :
%PSMatching(datatreatment=PNET._MIPD_YES, datacontrol=PNET._MIPD_NO,
method=NN, numberofcontrols=3, caliper=0.1, replacement=NO, out=MATCHES); RUN;
Any ideas?
Thanks,
J
@Jarot741 - Sorry, the techniques used in these macros are not my area of expertise. I'll leave it up to someone who has more knowledge about this.
FYI, all I did was search SAS Support to find the macro then used an example in the paper to show how it is run.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.