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

Hello, 

 

I've stratified my cohort into 5 strata (1-5) as part of a propensity analysis. As there is residual imbalance in some of the baseleine covariates within some strata, I would like to conduct regression within strata. 

 

I'm following an example analysis outlined by a textbook "Real World Health Care Data Analysis", but it runs into problems with the 'within-strata' regression for a binary outcome. The following code was forwarded as a way to output LSMEANS to a dataset for computation across strata. For example, the sample code would suggest the following:

 

proc genmod data=TXAstrat Descending;
by _strata_;
class TXAstatus sex / desc;
model Tx = TXAstatus age sex preopHb Anesth_LP Surg_LP / dist=bin link=identity;
lsmeans TXAstatus / pdiff om;
ODS output Diffs = lsmd;
run;

 

But by using the link = identity option (presumably to avoid computing the differences in log odds), but the model runs to issues with either non-convergence or "ERROR: The mean parameter is either invalid or at a limit of its range for some observations."

 

I've tried to get around this using the %Margins macro, but I don't know how to incorporate the 'by strata' component. I've tried the following code:

%Margins(data=TXAstrat,
class =TXAstatus sex,
response =Tx,
roptions =event='1',
model =TXAstatus sex age,
dist =binomial,
margins =TXAstatus,
at = _strata_,
options =diff cl)

 

This generates an error message "ERROR: Variable _STRATA_ not specified in MODEL=."

 

Any help would be very much appreciated!

 

Thanks in advance,
Brett

1 ACCEPTED SOLUTION

Accepted Solutions
StatDave
SAS Super FREQ

The Margins macro does not directly support BY processing like procedures do. You could create a subset data set for each _STRATA_ level and the run the macro on each. Alternatively, you can use the general method described this note which mimics BY processing for any macro. See the section titled "Adding BY processing to a macro". Using that method, the following runs the Margins macro once for each sex using the Neuralgia data in the first example shown in the Results tab of the Margins macro documentation

 

data Neur;
set Neuralgia;
NoPain=(pain='No');
run;
proc freq data=Neur;
table sex / out=MF;
run;
data _null_;
set MF;
call execute('data a; set Neur; where sex='''|| sex ||'''; run;
%nrstr(%margins(data=a, class=treatment, response=NoPain, roptions=event=''1'', dist=binomial, model=treatment age duration, margins=treatment))'
);
run;

 

View solution in original post

2 REPLIES 2
StatDave
SAS Super FREQ

The Margins macro does not directly support BY processing like procedures do. You could create a subset data set for each _STRATA_ level and the run the macro on each. Alternatively, you can use the general method described this note which mimics BY processing for any macro. See the section titled "Adding BY processing to a macro". Using that method, the following runs the Margins macro once for each sex using the Neuralgia data in the first example shown in the Results tab of the Margins macro documentation

 

data Neur;
set Neuralgia;
NoPain=(pain='No');
run;
proc freq data=Neur;
table sex / out=MF;
run;
data _null_;
set MF;
call execute('data a; set Neur; where sex='''|| sex ||'''; run;
%nrstr(%margins(data=a, class=treatment, response=NoPain, roptions=event=''1'', dist=binomial, model=treatment age duration, margins=treatment))'
);
run;

 

bretthouston
Obsidian | Level 7
Thanks - this is very helpful!

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
  • 2 replies
  • 1574 views
  • 2 likes
  • 2 in conversation