<?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: PROC SURVEYMEANS for multiple variables only with values above zero in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/678945#M32622</link>
    <description>&lt;P&gt;Subsetting data , as in WHERE or BY groups is not often a good idea.&lt;/P&gt;
&lt;P&gt;If you want to exclude a value from counting or summing for use in a Mean then it should be set to missing, not zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the actual relationship between ID1, ID2 and ID3 that these should be treated together in the manner you suggest?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This may not be a simple, i.e. one step, solution because of the way that the Survey procs treat the weights.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Aug 2020 17:31:16 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-08-24T17:31:16Z</dc:date>
    <item>
      <title>PROC SURVEYMEANS for multiple variables only with values above zero</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/678926#M32618</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to calculate the mean of multiple variables (VAR1, VAR2, VAR3), not by column or row, but all the values. For example, I would like to get the mean of 34, 45, 31, 35, 41 = 186/5 = 37.2&lt;/P&gt;&lt;P&gt;This is an example of the data&lt;BR /&gt;ID&amp;nbsp; VAR1 VAR2 VAR3&lt;BR /&gt;ID1&amp;nbsp; 34&amp;nbsp; &amp;nbsp;45&amp;nbsp; &amp;nbsp;0&lt;BR /&gt;ID2&amp;nbsp; 31&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 35&lt;BR /&gt;ID3&amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 41&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only have the code for a single variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SURVEYMEANS DATA=sample1 MEAN SUM VARMETHOD=BRR;&lt;BR /&gt;DOMAIN DHHDDRI;&lt;BR /&gt;WHERE VAR1 &amp;gt; 0;&lt;BR /&gt;VAR VAR1;&lt;BR /&gt;WEIGHT WTS_P;&lt;BR /&gt;REPWEIGHTS BSW1-BSW500;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 16:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/678926#M32618</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2020-08-24T16:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SURVEYMEANS for multiple variables only with values above zero</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/678945#M32622</link>
      <description>&lt;P&gt;Subsetting data , as in WHERE or BY groups is not often a good idea.&lt;/P&gt;
&lt;P&gt;If you want to exclude a value from counting or summing for use in a Mean then it should be set to missing, not zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the actual relationship between ID1, ID2 and ID3 that these should be treated together in the manner you suggest?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This may not be a simple, i.e. one step, solution because of the way that the Survey procs treat the weights.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 17:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/678945#M32622</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-24T17:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SURVEYMEANS for multiple variables only with values above zero</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/678957#M32626</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;How do I set to missing values?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;"What is the actual relationship between ID1, ID2 and ID3 that these should be treated together in the manner you suggest?&lt;/STRONG&gt;They are all types of fruits (g of fruits), but I want to know the mean for all fruits, not individual types of fruits.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;"This may not be a simple, i.e. one step, solution because of the way that the Survey procs treat the weights."&lt;/STRONG&gt; I agree, that is why I wanted to get experts' input.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 18:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/678957#M32626</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2020-08-24T18:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SURVEYMEANS for multiple variables only with values above zero</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/678966#M32628</link>
      <description>&lt;P&gt;What you might consider is turning your 'wide' dataset into a 'long' dataset and following&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;'s advice and set 0's to missing.&amp;nbsp; I am sure that other variables get carried along (like the sampling weights), but here is what I would do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_wide;
input ID $  VAR1 VAR2 VAR3;
datalines;:
ID1  34   45   0
ID2  31   0    35
ID3  0     0    41
;

data want_long;
set have_wide;
value=var1; varlevel ='VAR1'; output;
value=var2; varlevel ='VAR2'; output;
value=var3; varlevel ='VAR3'; output;
keep id varlevel value;
run;

data want_long2;
set want_long;
if value=0 then value=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, you can calculate overall means by ignoring varlevel, or varlevel means by including a CLASS statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Over all levels of varlevel */

PROC SURVEYMEANS DATA=want_long2 MEAN SUM VARMETHOD=BRR;
DOMAIN DHHDDRI;
VAR VALUE;
WEIGHT WTS_P;
REPWEIGHTS BSW1-BSW500;
RUN;

/* Means for each varlevel */
PROC SURVEYMEANS DATA=want_long2 MEAN SUM VARMETHOD=BRR;
CLASS VARLEVEL;
DOMAIN DHHDDRI;
VAR VALUE;
WEIGHT WTS_P;
REPWEIGHTS BSW1-BSW500;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I assume that DOMAIN, WEIGHT and REPWEIGHTS are fixed for any given ID.&amp;nbsp; If that is the case, then the conversion of wide to long shouldn't be too hard.&amp;nbsp; However, I have some fear about REPWEIGHTS.&amp;nbsp; Anything with 500 observations needs to be handled carefully.&amp;nbsp; A more complete example of your wide data would clear part of this up.&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>Mon, 24 Aug 2020 19:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/678966#M32628</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2020-08-24T19:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SURVEYMEANS for multiple variables only with values above zero</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/679000#M32639</link>
      <description>&lt;P&gt;Thank you so much! Your code worked perfectly. I added on the keep statement:&lt;/P&gt;&lt;P&gt;data want_long;&lt;BR /&gt;set sample1;&lt;BR /&gt;value=var1; varlevel='var1';output;&lt;BR /&gt;value=var2; varlevel='var2';output;&lt;BR /&gt;value=var3; varlevel='var3';output;&lt;BR /&gt;keep id DHHDDRI WTS_P BSW1-BSW500 varlevel value;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the below option you gave since we want to know the overall mean of values by ignoring specific varlevel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc surveymeans data=want_long2 mean sum varmethod=BRR;&lt;BR /&gt;domain DHHDDRI;&lt;BR /&gt;var value;&lt;BR /&gt;weight WTS_P;&lt;BR /&gt;repweights BSW1-BSW500;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, the domain, weight and repweights are fixed for ID. The conversion worked perfectly. This is a snapshot of our dataframe. I import data from excel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48594iC8D0D6025BA789D6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your code is what we needed. What do you think?&lt;/P&gt;&lt;P&gt;Thanks again for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 21:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/PROC-SURVEYMEANS-for-multiple-variables-only-with-values-above/m-p/679000#M32639</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2020-08-24T21:15:36Z</dc:date>
    </item>
  </channel>
</rss>

