<?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: Summing all variables with the same prefix from a %let statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291779#M60464</link>
    <description>&lt;P&gt;What about this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;FV_market=sum(of check_:&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Aug 2016 21:37:11 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-08-15T21:37:11Z</dc:date>
    <item>
      <title>Summing all variables with the same prefix from a %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291776#M60462</link>
      <description>&lt;P&gt;&lt;FONT face="book antiqua,palatino"&gt;Hello, I created the following grouping of variables:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; practice_size= doctors, nurses, patients; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; market=income, population, race; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; organization=med_school, multi_market, affiliation; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino" size="2"&gt;For each of the variables listed above, I then created a new variable called check_variablename. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="book antiqua,palatino" size="2"&gt;So I have check_doctors, check_nurses... check_affiliation. I am now trying to sum these check variables by the categories I created above. So I want FV_practice_size to be the sum of check_doctors, check_nurses, and check_patients. Is there a way to combine this "check" prefix with the %let statements. The following code is not functioning how I want it to. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; FV_new; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; FV_checks; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;FV_practice_size=sum(of check_&amp;amp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;practice_size.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;FV_organization=sum(of check_&amp;amp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;organization.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;FV_market=sum(of check_&amp;amp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;market.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="book antiqua,palatino"&gt;The data looks like this:&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;doctors comp_doctors check_doctors nurses comp_nurses check_nurses &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 90&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 500&amp;nbsp;&amp;nbsp;&amp;nbsp; 425&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 21:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291776#M60462</guid>
      <dc:creator>Mitchell16</dc:creator>
      <dc:date>2016-08-15T21:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Summing all variables with the same prefix from a %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291779#M60464</link>
      <description>&lt;P&gt;What about this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;FV_market=sum(of check_:&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 21:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291779#M60464</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-15T21:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Summing all variables with the same prefix from a %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291782#M60466</link>
      <description>&lt;P&gt;That would sum all the check variables, not just three check variables in the market category.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 22:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291782#M60466</guid>
      <dc:creator>Mitchell16</dc:creator>
      <dc:date>2016-08-15T22:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Summing all variables with the same prefix from a %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291783#M60467</link>
      <description>&lt;P&gt;Since you don't want to process the variable names by CHECK then I suggest that the process that created the variables should use the appropriate prefix Practice_doctor, Practice_Nurse, Practice_Patient, Market_Income, Market_population, Market_race.&lt;/P&gt;
&lt;P&gt;Then you could get the sums using the correct prefix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or possibly have a completely different structure such as&lt;/P&gt;
&lt;P&gt;Roll with values of practice, market or organization&lt;/P&gt;
&lt;P&gt;Group with the values like doctor, nurse, income, population, med_school media market&lt;/P&gt;
&lt;P&gt;and the last variable holding a (check?) value.&lt;/P&gt;
&lt;P&gt;Then Proc summary, means, report or tabulate would allow getting totals by the Roll variable and crossed with Group as needed.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 22:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291783#M60467</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-15T22:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Summing all variables with the same prefix from a %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291788#M60470</link>
      <description>&lt;P&gt;For the small number of variables you have, you might as well type out the list. &amp;nbsp;But if you are interested in extending your macro language skills (or if the lists are in reality much longer), you could take this approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Get rid of the commas in the values of the macro variables&lt;/LI&gt;
&lt;LI&gt;Apply the techniques outlined in the link below to have macro language construct your lists with "check_" in front of each name&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/publishing/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/" target="_blank"&gt;http://blogs.sas.com/content/publishing/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 22:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291788#M60470</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-15T22:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: Summing all variables with the same prefix from a %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291805#M60476</link>
      <description>&lt;PRE&gt;
You could change it before apply it .

%let practice_size= doctors, nurses, patients;
%let check=%sysfunc(prxchange(s/(\w+)/check_$1/,-1,%bquote(&amp;amp;practice_size)));

%put &amp;amp;check ;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Aug 2016 02:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-all-variables-with-the-same-prefix-from-a-let-statement/m-p/291805#M60476</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-16T02:43:32Z</dc:date>
    </item>
  </channel>
</rss>

