<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using margins macro to compute differences in probabilities within strata in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Using-margins-macro-to-compute-differences-in-probabilities/m-p/665051#M31692</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc genmod data=TXAstrat Descending;&lt;BR /&gt;by _strata_;&lt;BR /&gt;class TXAstatus sex / desc;&lt;BR /&gt;model Tx = TXAstatus age sex preopHb Anesth_LP Surg_LP / dist=bin link=identity; &lt;BR /&gt;lsmeans TXAstatus / pdiff om;&lt;BR /&gt;ODS output Diffs = lsmd;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;%Margins(data=TXAstrat,&lt;BR /&gt;class =TXAstatus sex,&lt;BR /&gt;response =Tx,&lt;BR /&gt;roptions =event='1',&lt;BR /&gt;model =TXAstatus sex age,&lt;BR /&gt;dist =binomial,&lt;BR /&gt;margins =TXAstatus,&lt;BR /&gt;at = _strata_,&lt;BR /&gt;options =diff cl)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This generates an error message "ERROR: Variable _STRATA_ not specified in MODEL=."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be very much appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;BR /&gt;Brett&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jun 2020 15:49:46 GMT</pubDate>
    <dc:creator>bretthouston</dc:creator>
    <dc:date>2020-06-25T15:49:46Z</dc:date>
    <item>
      <title>Using margins macro to compute differences in probabilities within strata</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Using-margins-macro-to-compute-differences-in-probabilities/m-p/665051#M31692</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc genmod data=TXAstrat Descending;&lt;BR /&gt;by _strata_;&lt;BR /&gt;class TXAstatus sex / desc;&lt;BR /&gt;model Tx = TXAstatus age sex preopHb Anesth_LP Surg_LP / dist=bin link=identity; &lt;BR /&gt;lsmeans TXAstatus / pdiff om;&lt;BR /&gt;ODS output Diffs = lsmd;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;%Margins(data=TXAstrat,&lt;BR /&gt;class =TXAstatus sex,&lt;BR /&gt;response =Tx,&lt;BR /&gt;roptions =event='1',&lt;BR /&gt;model =TXAstatus sex age,&lt;BR /&gt;dist =binomial,&lt;BR /&gt;margins =TXAstatus,&lt;BR /&gt;at = _strata_,&lt;BR /&gt;options =diff cl)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This generates an error message "ERROR: Variable _STRATA_ not specified in MODEL=."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be very much appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;BR /&gt;Brett&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 15:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Using-margins-macro-to-compute-differences-in-probabilities/m-p/665051#M31692</guid>
      <dc:creator>bretthouston</dc:creator>
      <dc:date>2020-06-25T15:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using margins macro to compute differences in probabilities within strata</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Using-margins-macro-to-compute-differences-in-probabilities/m-p/665158#M31697</link>
      <description>&lt;P&gt;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 &lt;A href="http://support.sas.com/kb/46847" target="_self"&gt;this note&lt;/A&gt; 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 &lt;A href="http://support.sas.com/kb/63038" target="_self"&gt;Margins macro documentation&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data Neur; &lt;BR /&gt;set Neuralgia; &lt;BR /&gt;NoPain=(pain='No'); &lt;BR /&gt;run;&lt;BR /&gt;proc freq data=Neur;&lt;BR /&gt;table sex / out=MF;&lt;BR /&gt;run;&lt;BR /&gt;data _null_;&lt;BR /&gt;set MF;&lt;BR /&gt;call execute('data a; set Neur; where sex='''|| sex ||'''; run;&lt;BR /&gt;%nrstr(%margins(data=a, class=treatment, response=NoPain, roptions=event=''1'', dist=binomial, model=treatment age duration, margins=treatment))'&lt;BR /&gt;);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 20:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Using-margins-macro-to-compute-differences-in-probabilities/m-p/665158#M31697</guid>
      <dc:creator>StatDave</dc:creator>
      <dc:date>2020-06-25T20:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using margins macro to compute differences in probabilities within strata</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Using-margins-macro-to-compute-differences-in-probabilities/m-p/665449#M31708</link>
      <description>Thanks - this is very helpful!</description>
      <pubDate>Fri, 26 Jun 2020 19:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Using-margins-macro-to-compute-differences-in-probabilities/m-p/665449#M31708</guid>
      <dc:creator>bretthouston</dc:creator>
      <dc:date>2020-06-26T19:50:42Z</dc:date>
    </item>
  </channel>
</rss>

