<?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: Dynamically select variables on which compute the mean in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642622#M191736</link>
    <description>&lt;P&gt;In my case, the columns were :&lt;/P&gt;&lt;P&gt;a_1, a_2, b_1, b_2, b_3 .... b_n&lt;/P&gt;&lt;P&gt;and I wanted to compute the mean on the "b" columns,&lt;/P&gt;&lt;P&gt;So&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s trick (before the edit) about using :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;mean(of b:)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;is perfect.&lt;BR /&gt;Thank you,&lt;/P&gt;&lt;P&gt;Gluttony&lt;/P&gt;</description>
    <pubDate>Fri, 24 Apr 2020 14:54:41 GMT</pubDate>
    <dc:creator>Gluttony</dc:creator>
    <dc:date>2020-04-24T14:54:41Z</dc:date>
    <item>
      <title>Dynamically select variables on which compute the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642600#M191721</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a macro which creates a dataset which size depends on the input :&lt;/P&gt;&lt;P&gt;Columns names : a_1, a_2, a_3, a_4 ... .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to compute the mean of all the columns but the first two in the macro :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want;
	SET have;
	mean_value=mean(a_3, a_4 ....);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I dynamically select the columns ? (I know all the columns' name)&lt;/P&gt;&lt;P&gt;Maybe with columns' index/position (Mean on the 3rd column to the last one) ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gluttony&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642600#M191721</guid>
      <dc:creator>Gluttony</dc:creator>
      <dc:date>2020-04-24T14:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically select variables on which compute the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642601#M191722</link>
      <description>&lt;P&gt;Well, if the variables of interest all begin with a_ then you can use something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;mean_value = mean(of a_3-a_19);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642601#M191722</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-24T14:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically select variables on which compute the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642603#M191724</link>
      <description>Thank you !!!!&lt;BR /&gt;That's perfect !&lt;BR /&gt;Gluttony</description>
      <pubDate>Fri, 24 Apr 2020 14:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642603#M191724</guid>
      <dc:creator>Gluttony</dc:creator>
      <dc:date>2020-04-24T14:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically select variables on which compute the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642608#M191727</link>
      <description>&lt;P&gt;Is your issue that you do not know how many a_ variables there are and need help determining that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will you guarantee that there will always be 3 or more values?&lt;/P&gt;
&lt;P&gt;Then perhaps:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array aa a_: ;
   mean_value = (sum (of aa(*)) - sum(a_1,a_2))/(n (of aa(*)) - 2);
run;&lt;/PRE&gt;
&lt;P&gt;but you would need to check how many values are in the AA array if you can't be sure there are always 3 or more.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642608#M191727</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-24T14:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically select variables on which compute the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642611#M191729</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is your issue that you do not know how many a_ variables there are and need help determining that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will you guarantee that there will always be 3 or more values?&lt;/P&gt;
&lt;P&gt;Then perhaps:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array aa a_: ;
   mean_value = (sum (of aa(*)) - sum(a_1,a_2))/(n (of aa(*)) - 2);
run;&lt;/PRE&gt;
&lt;P&gt;but you would need to check how many values are in the AA array if you can't be sure there are always 3 or more.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Doesn't work if a_1 and/or a_2 is missing, the denominator will be wrong.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642611#M191729</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-24T14:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically select variables on which compute the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642622#M191736</link>
      <description>&lt;P&gt;In my case, the columns were :&lt;/P&gt;&lt;P&gt;a_1, a_2, b_1, b_2, b_3 .... b_n&lt;/P&gt;&lt;P&gt;and I wanted to compute the mean on the "b" columns,&lt;/P&gt;&lt;P&gt;So&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s trick (before the edit) about using :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;mean(of b:)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;is perfect.&lt;BR /&gt;Thank you,&lt;/P&gt;&lt;P&gt;Gluttony&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642622#M191736</guid>
      <dc:creator>Gluttony</dc:creator>
      <dc:date>2020-04-24T14:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically select variables on which compute the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642625#M191739</link>
      <description>&lt;P&gt;as long as there are no other variables whose name starts with B in your data set, that would work. For example, if your data set also contains variable BirthYear then the B: in the MEAN function won't work.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:54:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642625#M191739</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-24T14:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically select variables on which compute the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642627#M191742</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is your issue that you do not know how many a_ variables there are and need help determining that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will you guarantee that there will always be 3 or more values?&lt;/P&gt;
&lt;P&gt;Then perhaps:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array aa a_: ;
   mean_value = (sum (of aa(*)) - sum(a_1,a_2))/(n (of aa(*)) - 2);
run;&lt;/PRE&gt;
&lt;P&gt;but you would need to check how many values are in the AA array if you can't be sure there are always 3 or more.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Doesn't work if a_1 and/or a_2 is missing, the denominator will be wrong.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yep.&lt;/P&gt;
&lt;P&gt;Incomplete data description =&amp;gt; incomplete response.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-select-variables-on-which-compute-the-mean/m-p/642627#M191742</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-24T14:56:49Z</dc:date>
    </item>
  </channel>
</rss>

