<?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 Covariate values in ESTIMATE statements when using a BY variable. in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Covariate-values-in-ESTIMATE-statements-when-using-a-BY-variable/m-p/907551#M45064</link>
    <description>&lt;P&gt;I am doing an analysis using a mixed model (PROC MIXED) on longitudinal data, wherein I'm running the model for different bootstraps/imputation combinations using a BY statement. Getting the LSMEANS from each is easy, and I can estimate the model mean AT any visit for all different values of my BY variables (bootstrap/imputation combo). SAS automatically plugs in the means of the other covariates BY the variables I have given to create different LSMEANS each time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, one estimate of interest is the mean OVER the first six visits. For a single analysis, I have previously used an ESTIMATE statement as shown in the code below, giving equal weight over the first six visits. To produce the mean, this ESTIMATE statement needs average values of my two continuous covariates (var1 and var2) explicitly plugged in, which here are assumed to be calculated previously and stored as macro variables&amp;nbsp;&amp;amp;mvar1 and&amp;nbsp;&amp;amp;mvar2; it is not automatically done like in LSMEANS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I most efficiently run the model over my BY variables (bootstrap sample/imputation combinations) using the mean of var1 and var2 for the specific bootstrap sample/imputation each time, the same way LSMEANS does automatically with the BY statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc mixed data=mydata method = reml;   
   by bootn imputen;                                                
   class subj trt visit;   
   model chg = trt|visit var1 var2   / ddfm=bw solution;
   repeated visit / type=un subject=subj;
   lsmeans trt|visit/ pdiff=all cl;
	          
  estimate 'TRT 1 Over First 6 visits'
       intercept 1   
       var1 &amp;amp;mvar1
       covar3 &amp;amp;mvar2
       visit 0.166666 0.166666 0.1666666 0.166666 0.166666 0.166666 0 0 0 0
       trt 1 0 0 0
       trt*visit 0.1666666 0.166666 0.166666 0.166666 0.166666 0.166666 0 0 0 0           0 0 0 0 0 0 0 0 0 0          0 0 0 0 0 0 0 0 0 0          0 0 0 0 0 0 0 0 0 0    /CL;  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Dec 2023 14:21:46 GMT</pubDate>
    <dc:creator>jesseh</dc:creator>
    <dc:date>2023-12-12T14:21:46Z</dc:date>
    <item>
      <title>Covariate values in ESTIMATE statements when using a BY variable.</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Covariate-values-in-ESTIMATE-statements-when-using-a-BY-variable/m-p/907551#M45064</link>
      <description>&lt;P&gt;I am doing an analysis using a mixed model (PROC MIXED) on longitudinal data, wherein I'm running the model for different bootstraps/imputation combinations using a BY statement. Getting the LSMEANS from each is easy, and I can estimate the model mean AT any visit for all different values of my BY variables (bootstrap/imputation combo). SAS automatically plugs in the means of the other covariates BY the variables I have given to create different LSMEANS each time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, one estimate of interest is the mean OVER the first six visits. For a single analysis, I have previously used an ESTIMATE statement as shown in the code below, giving equal weight over the first six visits. To produce the mean, this ESTIMATE statement needs average values of my two continuous covariates (var1 and var2) explicitly plugged in, which here are assumed to be calculated previously and stored as macro variables&amp;nbsp;&amp;amp;mvar1 and&amp;nbsp;&amp;amp;mvar2; it is not automatically done like in LSMEANS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I most efficiently run the model over my BY variables (bootstrap sample/imputation combinations) using the mean of var1 and var2 for the specific bootstrap sample/imputation each time, the same way LSMEANS does automatically with the BY statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc mixed data=mydata method = reml;   
   by bootn imputen;                                                
   class subj trt visit;   
   model chg = trt|visit var1 var2   / ddfm=bw solution;
   repeated visit / type=un subject=subj;
   lsmeans trt|visit/ pdiff=all cl;
	          
  estimate 'TRT 1 Over First 6 visits'
       intercept 1   
       var1 &amp;amp;mvar1
       covar3 &amp;amp;mvar2
       visit 0.166666 0.166666 0.1666666 0.166666 0.166666 0.166666 0 0 0 0
       trt 1 0 0 0
       trt*visit 0.1666666 0.166666 0.166666 0.166666 0.166666 0.166666 0 0 0 0           0 0 0 0 0 0 0 0 0 0          0 0 0 0 0 0 0 0 0 0          0 0 0 0 0 0 0 0 0 0    /CL;  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 14:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Covariate-values-in-ESTIMATE-statements-when-using-a-BY-variable/m-p/907551#M45064</guid>
      <dc:creator>jesseh</dc:creator>
      <dc:date>2023-12-12T14:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Covariate values in ESTIMATE statements when using a BY variable.</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Covariate-values-in-ESTIMATE-statements-when-using-a-BY-variable/m-p/907705#M45068</link>
      <description>I am not sure . You could try  LSMESTIMATE statement which like LSMEANS and no need to consider other two continuous covariates (var1 and var2) .  would handle by LSMESTIMATE itself .&lt;BR /&gt;LIke:&lt;BR /&gt;&lt;BR /&gt;lsmestimate trt*visit    ' mean OVER the first six visits'   1  1  1  1   1  1  / divisor=6  cl  ;&lt;BR /&gt;&lt;BR /&gt;But &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13633"&gt;@StatDave&lt;/a&gt;     &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15363"&gt;@SteveDenham&lt;/a&gt;      &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13758"&gt;@lvm&lt;/a&gt;     could give you right code.</description>
      <pubDate>Wed, 13 Dec 2023 05:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Covariate-values-in-ESTIMATE-statements-when-using-a-BY-variable/m-p/907705#M45068</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-12-13T05:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Covariate values in ESTIMATE statements when using a BY variable.</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Covariate-values-in-ESTIMATE-statements-when-using-a-BY-variable/m-p/908045#M45075</link>
      <description>&lt;P&gt;That is close,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;. All that needs done is to add in the continuous covariates using the AT option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;lsmestimate trt*visit 'Trt 1 mean OVER the first six visits' 1 1 1 1 1 1 0 0 0 0   0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;   0 0 0 0 0 0 0 0 0    0 0 0 0 0 0 0 0 0 0/ divisor=6 cl AT MEANS ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I added in the zeroes for the coefficients of the other lsmeans used in the LSMESTIMATE. That should make it easier if you have other treatment means or differences to estimate. The key here is the AT MEANS which applies the covariate adjustment using the mean of each continuous covariate in the model. Since this is being processed by bootstrap - imputation combination, each will be fit with different mean values. If you want the means over all bootstrap-imputation combinations, create the macro variable for each and change the AT MEANS to AT var1=&amp;amp;meanoverallvar1 covar3=&amp;amp;meanoverallvar2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SteveDenham&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 18:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Covariate-values-in-ESTIMATE-statements-when-using-a-BY-variable/m-p/908045#M45075</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2023-12-14T18:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Covariate values in ESTIMATE statements when using a BY variable.</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Covariate-values-in-ESTIMATE-statements-when-using-a-BY-variable/m-p/908063#M45078</link>
      <description>&lt;P&gt;This is perfect, thank you. I have used lsmestimate before, but it slipped my mind to use it in this way.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 20:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Covariate-values-in-ESTIMATE-statements-when-using-a-BY-variable/m-p/908063#M45078</guid>
      <dc:creator>jesseh</dc:creator>
      <dc:date>2023-12-14T20:10:43Z</dc:date>
    </item>
  </channel>
</rss>

