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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
No_ABD_for_me
Obsidian | Level 7

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

View solution in original post

14 REPLIES 14
sbxkoenk
SAS Super FREQ

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

No_ABD_for_me
Obsidian | Level 7

Hi Koen

 

Thanks for your reply! That was a good idea, but unfortunately, it didn't work for me

SASKiwi
PROC Star

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);
No_ABD_for_me
Obsidian | Level 7

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

 

Screen Shot 2021-11-09 at 4.33.16 PM.png

SASKiwi
PROC Star

@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
Obsidian | Level 7
OK got it. When rerunning that with OPTIONS MPRINT at the beginning, here are the errors that came up in the log

ERROR: Operand '*LIT1001'n does not have a value.
ERROR: (execution) Matrix has not been set to a value.
ERROR: (execution) Matrix has not been set to a value.
ERROR: (execution) Matrix has not been set to a value.

Along with a host of other error messages that I am certain do not apply (e.g., "ERROR: You requested a model involving W but did not provide a valid W variable name." "ERROR: One of more of your M variables is not listed in the variables list.")
SASKiwi
PROC Star

@No_ABD_for_me - Looks like you've got a problem with missing data values. You'll need to investigate and fix.

No_ABD_for_me
Obsidian | Level 7
Thanks for responding! I"m not sure I'm familiar with creating a view within SAS. How would I go about that?
No_ABD_for_me
Obsidian | Level 7

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.)
sbxkoenk
SAS Super FREQ

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

No_ABD_for_me
Obsidian | Level 7

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.

No_ABD_for_me
Obsidian | Level 7

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 14 replies
  • 1838 views
  • 0 likes
  • 4 in conversation