BookmarkSubscribeRSS Feed
pamplemouse22
Calcite | Level 5

Hello, 

 

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? 

Thank you!

11 REPLIES 11
ballardw
Super User

Use of macro has two part, first defining and compiling it make it ready in the session. That would be code that looks like

%macro macroname(parameters);

<assorted SAS code>

%mend;

 

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.

pamplemouse22
Calcite | Level 5

thank you! i found the script to define the macro. 

lindst801
Fluorite | Level 6

Hi I ran into this same issue as well when trying to replicate the macro. If you have the original script, would you be able to share the syntax? Thank you much appreciated. 

 

 

Reeza
Super User
Have you checked into PROC CAUSEMED? That may be what you want now instead?

https://support.sas.com/kb/59/081.html
lindst801
Fluorite | Level 6

Unfortunately, I need to be able to conduct mediation analysis with count data, so I am only able to use Poisson distribution for a binary variables. When I use PROC CAUSALMED, I am unable to get any other output except the CDE, NDS, and NIE transformed. Therefore, I need to be able to get CDE, NDE, and NIE with a Poisson distribution with a log link.

 

 

 

 

Reeza
Super User
Second link includes the source macro then.
Reeza
Super User
This site has the original paper and code.
You'll need to find the specific macro yourself though.
https://www.hsph.harvard.edu/tyler-vanderweele/tools-and-tutorials/
Astounding
PROC Star

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).

pamplemouse22
Calcite | Level 5

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;
Reeza
Super User

Macro definition - needs to be run first

%macro print(dataset_name);

proc print data=&dataset_name noobs label;
run;

%mend;

Macro execution:

 

%print(sashelp.class);

 

pamplemouse22
Calcite | Level 5

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 11 replies
  • 1981 views
  • 0 likes
  • 5 in conversation