06-08-2017 04:54 PM
I am having trouble using a SAS macro that was described in a paper. Can you please tell me what step I am missing? Thank you.
From Valeri 2013: The macro has been developed using SAS Version 9.2. In order to implement mediation analysis via the mediation macro in SAS the investigator first opens a new SAS session and inputs the data, which has to include the outcome, treatment and mediator variables as well as the covariates to be adjusted for in the model. Macro activation requires then the investigator to save the macro script and input information in the statement:
%mediation(data= ,yvar= ,avar= ,mvar= ,cvar= ,a0= ,a1= ,m= ,nc= ,yreg= ,mreg= ,interaction=) run;
So, I prepped my dataset and plugged in the values needed for the macro like this (values aren't important here, i just want to know how to ues this macro.
%mediation(data=test, yvar=outcome, avar=exposure, mvar=med, cvar=cov, a0=0, a1=1, m=1, nc=1, yreg=logistic, mreg= logistic, interaction=false) run;
Then, I get the following error:
WARNING: Apparent invocation of macro MEDIATION not resolved. ERROR 180-322: Statement is not valid or it is used out of proper order.
What am I doing wrong? Do I have to define the macro elsewhere? How does SAS know what to do with this macro?
06-08-2017 05:09 PM
Use of macro has two part, first defining and compiling it make it ready in the session. That would be code that looks like
<assorted SAS code>
you would Execute that block of code before using it as
%macroname(a b c);
to use the value a b c as parameter to the macro.
You will get the error you reference when the compile step has not be executed OR if there was an error when attempting to compile it.
06-08-2017 05:31 PM
It sounds like the piece you are missing is this:
"Macro activation requires then the investigator to save the macro script ... "
Did you get a copy of the macro and save it somewhere? Did you identify to the program where the macro is stored?
If you did save the macro, the simplest way to define it to your program would be to add one line:
%include "path to the file holding the macro code";
That being done, you should be able to use the macro later in the same program (or in the same EG session).
06-09-2017 01:40 PM
thank you! i found the script that defines the macro. Now that I have it, the macro definition is very long and takes me about an hour to run each time. do you have suggestions to make this process faster? It's a series of proc reg. I suppressed output to make it run faster, using the followng code. Any other tips?
ODS LISTING close; ODS RESULTS OFF;
06-09-2017 01:41 PM
thank you! i found the original macro definition and am trying to run that first. Any tips to make the run time shorter for this macro? I don't want ot delete out any of the comments.
I included this at at the top which is helping some, but it still takes about an hour to run, each time.
ODS LISTING close;
ODS RESULTS OFF;