BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ancfletcher
Calcite | Level 5

 

Moved from this old thread:  https://communities.sas.com/t5/SAS-Enterprise-Guide/gmatch-macros-don-t-output-data/m-p/417168#M2685...

 

Hey there! I am trying to use the same macro and am having similar difficulty of having no output data. I am relatively new to SAS and trying to teach myself how to do propensity scoring. 

 

I am using the Paper 689-2017 "A Practical Guide to Getting Started with Propensity Scores" which has been extremely helpful.
 
I successfully created a propensity score variable (ps) via:
 
proc logistic data=albumin.albumin;
class gender smoking diabetes ; 
model readmission = albuminpre gender BMI age smoking diabetes/
link=glogit rsquare;
output out = ps_los pred = ps xbeta=logit_ps;
run;
 
But have been unsuccessfully able to use the macro. I have tried both the Duke and Mayo version macros:
 
I am using the Duke code: 
 
%macro gmatch(
inds =albumin.albumin ,
matchvar = ps,
groupvar = readmission ,
idvar = MRN ,
stratvar = NONE,
caliper = NONE,
caliper_type = ABS,
randseed = -1,
ncntls = 1,
outlinks = _OUTLINKS,
outds = _OUTMATCH,
);
 
It runs quickly and without error. It is my understanding that this is defining my macro? Then if I try to call on the macro (as  below), nothing happens or I get the error 
 
%gmatch(
inds =albumin.albumin ,
matchvar = ps,
groupvar = readmission ,
idvar = MRN ,
stratvar = NONE,
caliper = NONE,
caliper_type = ABS,
randseed = -1,
ncntls = 1,
outlinks = _OUTLINKS,
outds = _OUTMATCH,
);
 
 
ERROR
 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 %gmatch(
74 inds =albumin.albumin ,
75 matchvar = ps,
76 groupvar = readmission ,
77 idvar = MRN ,
78 stratvar = NONE,
79 caliper = NONE,
80 caliper_type = ABS,
ERROR: All positional parameters must precede keyword parameters.
81 randseed = -1,
82 ncntls = 1,
83 outlinks = _OUTLINKS,
84 outds = _OUTMATCH,
85 );
86
87
88 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
100
 
I honestly don't even know if I am inputing my variables correctly....I would imagine I use my created propensity score “ps” variable for the mvars, but am unsure what to use for the group (?readmission) and ID (something unique to each record- patient,  MRN?).  
 
The question I am trying to answer is if albumin is still a significant predictor for hospital readmission when controlling for other covariates. ( I have a lot of independent variables, but just keeping it simple with a few for now). 
 
Thank you for your time and consideration. I appreciate any guidance. 
 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

SAS now has the PSMATCH procedure which should be your starting point, if you have SAS 9.4 TS1M5+. 

 

This link has fully worked examples about half way down. 

https://support.sas.com/rnd/app/stat/procedures/psmatch.html

PSMATCH Procedure


The PSMATCH procedure provides a variety of tools for performing propensity score analysis. The PSMATCH procedure reduces the effects of confounding in nonrandomized trials or observational studies where the subjects are not randomly assigned to the treatment and control groups.

The PSMATCH procedure computes propensity scores, which estimate the probability that a subject is assigned to treatment given a set of pretreatment (baseline) covariates. The following methods for using the propensity scores to adjust the data for valid estimation of treatment effect are available:

  • Inverse probability of treatment weighting and weighting by the odds.
  • Stratification of observations that have similar propensity scores. In a subsequent outcome analysis, the treatment effect can be estimated within each stratum, and the estimates can be combined across strata to compute an average treatment effect.
  • Matching treated unit with one or more control units that have a similar value of the propensity score.
  • Methods of matching include:
    • fixed ratio matching
    • variable ratio matching
    • full matching

Provides various plots for assessing balance. Included plots are:

  • cloud plots, which are scatter plots in which the points are jittered to prevent overplotting
  • box plots for continuous variables
  • bar charts for classification variables
  • a standardized differences plot that summarizes differences between the treated and control groups

The PSMATCH procedures saves propensity scores and weights in an output data set that contains a sample that has been adjusted either by weighting, stratification, or matching. If the sample is stratified, you can save the strata identification in the output data set. If the sample is matched, you can save the matching identification in the output data set.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @ancfletcher and welcome to the SAS Support Communities!

 

The error message is caused by the comma following "_OUTMATCH" at the end of the macro call. SAS interprets the null value following it as (the value of) a positional parameter, which would need to be specified before the keyword parameters inds, matchvar, etc. But of course, there is no positional parameter defined in this macro. So, as a first step, just delete this comma.

 

In fact, the comma at the end of the macro definition should be deleted as well because it is unnecessary and (as we've seen) misleading. Another weakness of the macro which I've noticed is that the final PROC DATASETS step is closed with a RUN statement rather than QUIT. I'd recommend to replace that run; by quit; and then rerun the macro definition from %macro ... to %mend; (not only the header %macro gmatch(...);!) before submitting the macro call (%gmatch(...)) again. Please note that by inserting parameter values (such as albumin.albumin) into the macro definition you define these values as default values for the respective parameters. Normally you would leave the macro definition unchanged and supply the parameter values only in the macro call. (Edit: Some default values were defined in the original macro definition, e.g. NONE for parameter stratvar. This means that you could omit "stratvar = NONE," etc. in the macro call, but it doesn't matter if you repeat these parameter assignments again.)

 

I can't run this macro successfully because it uses PROC IML and I don't have a SAS/IML license. Without delving deeper into propensity score matching I can't help you with your statistical questions about the macro, sorry. Hopefully someone else chimes in.

 

At least you should now be able to run the macro without syntax errors. Otherwise, please don't hesitate to ask again.

Reeza
Super User

SAS now has the PSMATCH procedure which should be your starting point, if you have SAS 9.4 TS1M5+. 

 

This link has fully worked examples about half way down. 

https://support.sas.com/rnd/app/stat/procedures/psmatch.html

PSMATCH Procedure


The PSMATCH procedure provides a variety of tools for performing propensity score analysis. The PSMATCH procedure reduces the effects of confounding in nonrandomized trials or observational studies where the subjects are not randomly assigned to the treatment and control groups.

The PSMATCH procedure computes propensity scores, which estimate the probability that a subject is assigned to treatment given a set of pretreatment (baseline) covariates. The following methods for using the propensity scores to adjust the data for valid estimation of treatment effect are available:

  • Inverse probability of treatment weighting and weighting by the odds.
  • Stratification of observations that have similar propensity scores. In a subsequent outcome analysis, the treatment effect can be estimated within each stratum, and the estimates can be combined across strata to compute an average treatment effect.
  • Matching treated unit with one or more control units that have a similar value of the propensity score.
  • Methods of matching include:
    • fixed ratio matching
    • variable ratio matching
    • full matching

Provides various plots for assessing balance. Included plots are:

  • cloud plots, which are scatter plots in which the points are jittered to prevent overplotting
  • box plots for continuous variables
  • bar charts for classification variables
  • a standardized differences plot that summarizes differences between the treated and control groups

The PSMATCH procedures saves propensity scores and weights in an output data set that contains a sample that has been adjusted either by weighting, stratification, or matching. If the sample is stratified, you can save the strata identification in the output data set. If the sample is matched, you can save the matching identification in the output data set.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1437 views
  • 1 like
  • 3 in conversation