<?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 Re: How to format estimate statement to get a mean across non-empty cells in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-format-estimate-statement-to-get-a-mean-across-non-empty/m-p/938615#M46829</link>
    <description>Try option OM+BYLEVEL :&lt;BR /&gt;&lt;BR /&gt;lsmeans species /stderr tdiff pdiff cl  om bylevel ;&lt;BR /&gt;</description>
    <pubDate>Thu, 08 Aug 2024 02:47:28 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-08-08T02:47:28Z</dc:date>
    <item>
      <title>How to format estimate statement to get a mean across non-empty cells</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-format-estimate-statement-to-get-a-mean-across-non-empty/m-p/938553#M46826</link>
      <description>&lt;P&gt;Hello, I know there are similar questions on this forum but being a SAS noob, I have been unable to get anything to work for my particular use case. Below I provide a simple example dataset that illustrates the issue. I have an "unbalanced" dataset where I have 3 species, sp1, sp2, and sp3, for which biomass was measured. But sp1 was measured in months 6,7,8,9 while sp2 and sp3 were not measured in month 6 but only in 7,8,9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand why the lsmeans statement returns non-estimable for species 2 and 3 because you cannot get a least-square mean over empty cells. However I want to write an estimate statement to get means for sp2 and sp3, only over months 7,8,9 and not considering month 6. I still get non-estimable in that case. I don't understand whether I am writing the statement incorrectly or whether I am misunderstanding what the estimate statement is doing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA example;
INPUT pasture $ block $ month $ year $ species $ biomass;
cards;
3	1	6	2021	sp1		745
6	2	6	2021	sp1		1011
9	3	6	2021	sp1		1129
3	1	7	2021	sp1		1612
6	2	7	2021	sp1		2034
9	3	7	2021	sp1		2210
3	1	8	2021	sp1		2795
6	2	8	2021	sp1		2975
9	3	8	2021	sp1		2699
3	1	9	2021	sp1		499
6	2	9	2021	sp1		624
9	3	9	2021	sp1		759
1	1	7	2021	sp2		2422
2	1	7	2021	sp3 	2685
4	2	7	2021	sp3 	1276
5	2	7	2021	sp2		2303
7	3	7	2021	sp2		2269
8	3	7	2021	sp3		784	
1	1	8	2021	sp2		6833
2	1	8	2021	sp3		3604
4	2	8	2021	sp3		2231
5	2	8	2021	sp2		8447
7	3	8	2021	sp2		6303
8	3	8	2021	sp3		1656
1	1	9	2021	sp2		3675
2	1	9	2021	sp3		1129
4	2	9	2021	sp3		1552
5	2	9	2021	sp2		6495
7	3	9	2021	sp2		5575
8	3	9	2021	sp3		647	
;

proc glimmix data=example;
    class species month pasture block;
    model biomass=species|month / e dist=gamma link=log s;
    random pasture(block);
	lsmeans species; * Species 2 and 3 are not estimable which makes sense because they have no data for month 6;
	estimate "Species 2, only months 7-9" species 0 1 0 month 0 1 1 1; * Also not estimable but I don't understand why not because I am not averaging over any empty cells;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Aug 2024 15:33:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-format-estimate-statement-to-get-a-mean-across-non-empty/m-p/938553#M46826</guid>
      <dc:creator>quentinread</dc:creator>
      <dc:date>2024-08-07T15:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to format estimate statement to get a mean across non-empty cells</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-format-estimate-statement-to-get-a-mean-across-non-empty/m-p/938615#M46829</link>
      <description>Try option OM+BYLEVEL :&lt;BR /&gt;&lt;BR /&gt;lsmeans species /stderr tdiff pdiff cl  om bylevel ;&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Aug 2024 02:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-format-estimate-statement-to-get-a-mean-across-non-empty/m-p/938615#M46829</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-08-08T02:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to format estimate statement to get a mean across non-empty cells</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-format-estimate-statement-to-get-a-mean-across-non-empty/m-p/938651#M46834</link>
      <description>&lt;P&gt;Thank you for this very helpful comment! It got me 99% of the way there. The bylevel option did not give me exactly what I wanted because I wanted the lsmean of each species only across the months 7-9 cells. Using bylevel gives the correct lsmean for species 2 and 3 but not species 1. But your suggestion to use OM inspired me to look in the documentation. I found that creating a new dataset for obsmargins that does not include month 6, and passing that as the obsmargins dataset in proc plm, I can get the correct lsmeans that I was looking for, see code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data nojune; set example;
  where month &amp;lt;&amp;gt; '6';
run;

proc glimmix data=example;
  class species month pasture block;
  model biomass=species|month / dist=gamma link=log;
  random pasture(block);
  store out=examplemod;
run;

proc plm restore=examplemod;
  lsmeans species / cl obsmargins=nojune pdiff adjust=tukey;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Aug 2024 11:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-format-estimate-statement-to-get-a-mean-across-non-empty/m-p/938651#M46834</guid>
      <dc:creator>quentinread</dc:creator>
      <dc:date>2024-08-08T11:36:12Z</dc:date>
    </item>
  </channel>
</rss>

