Hi,
I ran the Preacher and Hayes mediation macro, which itself worked fine. Now I am trying to run mediation analyses on my dataset where PEDQ is the predictor, OGPA is the outcome, and dummy coded race variables, DEMO_GENDER, and EDLEVEL are covariates. I used the macro below, which worked fine.
%process (data = rs.t1, vars = pedq safe se ogpa dblack dlatino dasian dmixed demo_gender edlevel,
y=ogpa, x=pedq, m=safe se, model=4, total=1, contrast=1, normal = 1, percent=1, boot= 5000, conf=95);
However, this ran the analysis for the entire sample. I would like to run it on my analytic sample, which is obtained using the following WHERE statement.
where pedq ne . and iai ne . and pals ne . and safe ne . and se ne . and ogpa ne . and ogpa ne 0.
My question is, how do I merge the 2 syntax statements above? In essence, where would the WHERE statement fit in the mediation syntax?
Thanks in advance for your help.
It worked! I deleted the observations that would have been excluded by my WHERE statement using this syntax
PROC SQL;
DELETE FROM rs.t1
WHERE pedq = .
;
QUIT;
PROC SQL;
DELETE FROM rs.t1
WHERE ogpa = .
;
QUIT;
PROC SQL;
DELETE FROM rs.t1
WHERE ogpa = 0
;
QUIT;
After the unwanted observations were removed, I ran the mediation syntax, and it worked beautifully on solely my analytic sample. Hoorah
Hello,
I do not know that macro but I guess you can apply the where clause to your input data set like this:
%process (data = rs.t1(where=(pedq ne . and iai ne . and pals ne . and safe ne . and se ne . and ogpa ne . and ogpa ne 0.))
, vars = pedq safe se ogpa dblack dlatino dasian dmixed demo_gender edlevel,
y=ogpa, x=pedq, m=safe se, model=4, total=1, contrast=1, normal = 1, percent=1, boot= 5000, conf=95);
Koen
Hi Koen
Thanks for your reply! That was a good idea, but unfortunately, it didn't work for me
Most likely SAS was confused by the extra brackets. How about this?
%process (data = %str(rs.t1(where= %(pedq ne . and iai ne . and pals ne . and safe ne . and se ne . and ogpa ne . and ogpa ne 0.)) )
, vars = pedq safe se ogpa dblack dlatino dasian dmixed demo_gender edlevel,
y=ogpa, x=pedq, m=safe se, model=4, total=1, contrast=1, normal = 1, percent=1, boot= 5000, conf=95);
Sorry for the delay! Well, that certainly did something, even if not the intended result, so we may be headed in the right direction. I received a different error message this time
@No_ABD_for_me - You are going to have to look through the SAS log to see what's causing those errors. Add this to the start of the program - OPTIONS MPRINT; - then rerun the macro to see the generated SAS code. That should give you more clues as to what is going on.
@No_ABD_for_me - Looks like you've got a problem with missing data values. You'll need to investigate and fix.
Create a view that manages the WHERE, and use that for the data= parameter of the macro.
Either
data viewname / view=viewname;
or
proc sql;
create view viewname as
....
Thank you. Does this look correct?
proc sql;
create view viewname as rs.t1 (where pedq ne . and iai ne . and pals ne . and safe ne .
and se ne . and ogpa ne . and ogpa ne 0.)
Nope.
This is better :
proc sql noprint;
create view viewname as
select *
from rs.t1
where pedq ne . and iai ne . and pals ne .
and safe ne . and se ne . and ogpa ne . and ogpa ne 0
; QUIT;
Koen
I truly appreciate you all for jumping in and offering your assistance! Unfortunately, it seems this has gotten much too complicated, and my dataset isn't cooperating with your helpful suggestions. I think I will try a new route and create a secondary dataset that deletes the observations that I am attempting to exclude by means of my WHERE statement. If I delete these observations completely, I may be able to run the mediation syntax on the dataset with no issue.
It worked! I deleted the observations that would have been excluded by my WHERE statement using this syntax
PROC SQL;
DELETE FROM rs.t1
WHERE pedq = .
;
QUIT;
PROC SQL;
DELETE FROM rs.t1
WHERE ogpa = .
;
QUIT;
PROC SQL;
DELETE FROM rs.t1
WHERE ogpa = 0
;
QUIT;
After the unwanted observations were removed, I ran the mediation syntax, and it worked beautifully on solely my analytic sample. Hoorah
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.