BookmarkSubscribeRSS Feed
Ashwini_uci
Obsidian | Level 7

Hello,

This question is for those with expertise in PSM analyses and macro.

I have been working on this propensity Score matching analyses for the first time and found a paper that provides a macro for PSM, attached below. The paper  provides the SAS code and the Macro which I am trying to run.

I have started working on the macro and creating all required variables. I am following all the steps given in this paper.

But in the last step, when I try to run the macro, the log shows me following error; I do not know about macros and I cannot really locate or identify any error, if there is any.

ERROR: The keyword parameter PAT_PSVAR was not defined with the macro.

Appreciate if you would please take a look at the macro and check if this variable is defined in the macro or if I am doing anything wrong, and if the variable is not defined in the macro, can you help me define it.

Has anyone referred to this paper to perform PSM analyses?

Is there any other simple way to perform the PSM analyses for someone like who who is not familiar with macros at all?


Any advice/help/guidance would be highly appreciated!


Thanks much!

Ashwini

5 REPLIES 5
Tom
Super User Tom
Super User

Looking at the code in PDF file you attached I can see that PAT_PSVAR is definitely intended to be defined as a parameter.

But notice that the second line is missing the slash to end the in-line comment.  This will have the effect of "eating" the third line which is where PAT_PSVAR is defined.

Corrected %macro statement is below.

%macro psmatch_multi(pat_dsn =, /* Name of data set with patient data */

pat_idvar=, /* Name of Patient ID variable in data set &PAT_DSN */

pat_psvar=, /* Name of Propensity Score variable in data set &PAT_DSN */

cntl_dsn=, /* Name of data set with control data */

cntl_idvar=, /* Name of Control ID variable in data set &CNTL_DSN */

cntl_psvar=, /* Name of Propensity Score variable in data set &CNTL_DSN */

match_dsn=, /* Name of output data set with N:1 matches */

match_ratio=, /* Number of control matches per patient */

score_diff=, /* Maximum allowable absolute differences between propensity scores*/

seed=1234567890) /* Optional input seed for random number generator */

;

Ashwini_uci
Obsidian | Level 7

Hi!, Thanks for your help. I did correct that in the macro, but still it shows the same warning..

Maybe there's something missing in the actual macro, I mean inside those loops..


Tom
Super User Tom
Super User

Could be, but the error message was very specific that it was because the parameter was not defined.

Make sure you have not introduced un wanted semi-colons into the modified code.  The code I posted above is one statement so there should only be one semi-colon.  Also make sure you do not have multiple copies of the macro definition or un wanted %MACRO statements that might be re-defining the macro.

You also might want to close SAS and start over so that you can eliminate to possibility that because of the unbalanced comment blocks you have gotten SAS confused about what is code and what is comment or what is macro definition and what are calls.

Ashwini_uci
Obsidian | Level 7

Hi Tom,

I verified the macro, restarted SAS. and tried to run it again, but now it shows me some more errors.

I have attached the error log to the original post.

I am also attaching the SAS code to run the macro and how I have modified the SAS code ..

Would you please take a look at the SAS code and the error log and let me know if the SAS code, I have modified, is correct and why I am getting those errors? That would be a great help!

Tom
Super User Tom
Super User

The error message is because the variable name you gave the macro was not on the dataset you gave it.  Sounds more like a mixup in your call than in the macro itself. 

25 The SAS System 18:31 Monday, June 17, 2013

ERROR: Column pat_id could not be found in the table/view identified with the correlation name P.

ERROR: Column pat_id could not be found in the table/view identified with the correlation name P.

ERROR: Column pat_id could not be found in the table/view identified with the correlation name C.

ERROR: Column pat_id could not be found in the table/view identified with the correlation name C.

NOTE: PROC SQL set option NOEXEC

Once it has that error the rest of the macro will fail because the dataset was not created.

It is hard to tell how that might have happened from the log you pasted as it is missing the first 24 pages.  The MPRINT option is a good way to see the code that the macro has generated and makes the LOG easier to read.  It should be easier to see where the macro is generating the wrong code with MPRINT turned on.

There are a number of places where there are opening /* comments without matching */ to end them. 

You should avoid using /* */ comments.  The only place I use them is when I want to embed a comment in the middle of a single statement such as in the %MACRO statement or in a really long comment block at the top of a program so that I can paste in actual example usage code with semi-colons. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

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.

Discussion stats
  • 5 replies
  • 2970 views
  • 0 likes
  • 2 in conversation