<?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: Do loop sum variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395194#M95259</link>
    <description>I'm getting the error message (biop_pr is my var name for start number and biop is my variable for the stop value).&lt;BR /&gt;NOTE: Character values have been converted to numeric values at the places given by:&lt;BR /&gt;      (Line):(Column).&lt;BR /&gt;      613:14&lt;BR /&gt;NOTE: Variable hmo_biop_pr is uninitialized.&lt;BR /&gt;NOTE: Variable hmo_biop is uninitialized.&lt;BR /&gt;</description>
    <pubDate>Tue, 12 Sep 2017 18:03:43 GMT</pubDate>
    <dc:creator>weweaw</dc:creator>
    <dc:date>2017-09-12T18:03:43Z</dc:date>
    <item>
      <title>Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395184#M95251</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I bet this is easy but I've been failing for a while now so maybe someone can help me. Below is sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 720pt;" border="0" width="960" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" width="64" /&gt; &lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;COL style="width: 48pt;" span="12" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="width: 48pt;"&gt;H-Start&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="width: 48pt;"&gt;H-End&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_1&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_2&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_3&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_4&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_5&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_6&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_7&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_8&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_9&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_10&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_11&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;6&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;5&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;C&lt;/TD&gt;
&lt;TD align="right"&gt;9&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to sum the H_# for certain ranges. &amp;nbsp;The variable H-Start has the start H value and H-End has the end. &amp;nbsp;For ID &amp;nbsp;'A' I&amp;nbsp;want to sum H_3 through&amp;nbsp;H_6. I've been trying to write a do loop and macros to solve this but have been failing. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like the output to look like this:&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 768pt;" border="0" width="1024" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" width="64" /&gt; &lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;COL style="width: 48pt;" span="13" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="width: 48pt;"&gt;H-Start&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="width: 48pt;"&gt;H-End&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_1&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_2&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_3&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_4&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_5&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_6&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_7&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_8&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_9&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_10&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_11&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;H_12&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;Want_Sum&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;6&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;5&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;9&lt;/TD&gt;
&lt;TD align="right"&gt;12&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 17:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395184#M95251</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2017-09-12T17:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395186#M95252</link>
      <description>&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; have;&lt;/P&gt;&lt;P&gt;input ID $ H_Start&amp;nbsp;&amp;nbsp;&amp;nbsp; H_End H_1&amp;nbsp; H_2&amp;nbsp; H_3&amp;nbsp; H_4&amp;nbsp; H_5&amp;nbsp; H_6&amp;nbsp; H_7&amp;nbsp; H_8&amp;nbsp; H_9&amp;nbsp; H_10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; H_11 H_12;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;C&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;if id='A' then sum=sum(of h_3--h_6);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 17:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395186#M95252</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-12T17:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395187#M95253</link>
      <description>Hi,&lt;BR /&gt;Sorry, maybe I wasn't clear.  I want to add a variable to sum the specific H_# for each person.  My real data has about 30K ID's and 60 H values. &lt;BR /&gt;Thanks.&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Sep 2017 17:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395187#M95253</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2017-09-12T17:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395188#M95254</link>
      <description>&lt;P&gt;Please provide a sample of your output table. Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 17:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395188#M95254</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-12T17:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395189#M95255</link>
      <description>&lt;P&gt;I added my wanted output to the original post.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 17:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395189#M95255</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2017-09-12T17:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395190#M95256</link>
      <description>&lt;P&gt;With 60 H variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array h_ {60};&lt;/P&gt;
&lt;P&gt;total_h = 0;&lt;/P&gt;
&lt;P&gt;if (1 &amp;lt;= h_start &amp;lt;= 60) and (1 &amp;lt;= h_end &amp;lt;= 60) then do _n_=h_start to h_end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; total_h + h_{_n_};&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 17:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395190#M95256</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-12T17:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395192#M95258</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array _h(*) h_1 - h_12;

total_sum = 0;

do i=h_start to H_end;
total_sum = sum(total_sum, _h(i));
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Sep 2017 18:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395192#M95258</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-12T18:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395194#M95259</link>
      <description>I'm getting the error message (biop_pr is my var name for start number and biop is my variable for the stop value).&lt;BR /&gt;NOTE: Character values have been converted to numeric values at the places given by:&lt;BR /&gt;      (Line):(Column).&lt;BR /&gt;      613:14&lt;BR /&gt;NOTE: Variable hmo_biop_pr is uninitialized.&lt;BR /&gt;NOTE: Variable hmo_biop is uninitialized.&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Sep 2017 18:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395194#M95259</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2017-09-12T18:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395195#M95260</link>
      <description>&lt;P&gt;I'm confused. For every ID there is a different start and stop H variables. For "do i=h_start to H_end;" What do I put in the '_start' and the '_end'?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit again to add the post I was referring&amp;nbsp;to.&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; _h&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; h_1 &lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt; h_12&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

total_sum &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

do i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;h_start to H_end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
total_sum &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;sum&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;total_sum&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; _h&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited to add:&lt;/P&gt;
&lt;P&gt;For A I&amp;nbsp;need it to sum H_3 throught&amp;nbsp;H_6, for B I need it to add H_2 though H_5, and C would be H_9 through H_12. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable H-Start is the number of H_# I want it to begin summing and the variable H-end has the H I want it to stop at.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 18:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395195#M95260</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2017-09-12T18:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395197#M95262</link>
      <description>&lt;P&gt;This error message says you got it wrong.&amp;nbsp; Your data set does not contain variables named HMO_BIOP_PR or HMO_BIOP.&amp;nbsp; Maybe you spelled the variable names wrong.&amp;nbsp; Or maybe you chose the wrong data set.&amp;nbsp; But those variables don't exist in the data set that you are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If possible, it would be more helpful if you were to post the log so we can see any errors in context.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 18:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395197#M95262</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-12T18:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395200#M95263</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28891"&gt;@weweaw&lt;/a&gt; wrote:&lt;BR /&gt;I'm confused. For every ID there is a different start and stop H variables.&amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's why you use the variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28891"&gt;@weweaw&lt;/a&gt; wrote:&lt;BR /&gt;. For "do i=h_start to H_end;" What do I put in the '_start' and the '_end'?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There are several solutions so we don' tknow which you're referring to.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's best if you post your full code and log if you're having issues.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 18:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395200#M95263</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-12T18:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395203#M95264</link>
      <description>Sorry I was using my ready data H_# is hmo_# and biop_pr is for the H-start and biop is for the H-stop.</description>
      <pubDate>Tue, 12 Sep 2017 18:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395203#M95264</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2017-09-12T18:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395205#M95265</link>
      <description>&lt;P&gt;Ok, I see where I changed it wrong. No error but total_sum is 0 for everything now and the other new variable i has odd numbers that my data could not sum to.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data t3;&lt;BR /&gt;set try1;&lt;/P&gt;
&lt;P&gt;array _h(*) hmo_1 - hmo_60;&lt;/P&gt;
&lt;P&gt;total_sum = 0;&lt;/P&gt;
&lt;P&gt;do i=biop_pr to biop;&lt;BR /&gt;total_sum = sum(total_sum, _h(i));&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 18:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395205#M95265</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2017-09-12T18:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395209#M95267</link>
      <description>&lt;P&gt;The variable i can be ignored.&amp;nbsp; It will always be equal to BIOP + 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a couple of primary possibilities to explain your results.&amp;nbsp; First and foremost, are the variable names HMO_1, HMO_2, etc. the proper names of existing variables in your data set?&amp;nbsp; (Is it possible they are spelled incorrectly and should really be H_1, H_2, etc.?)&amp;nbsp; And secondly, if you do have the proper names, are they always either 0 or a missing value for the relevant range of variables (from BIOP_PR to BIOP)?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 18:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395209#M95267</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-12T18:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop sum variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395218#M95269</link>
      <description>&lt;P&gt;Ok...given that it works for the sample data it's a bit hard to say what's wrong with yours.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Check correct variable mappings in all places&lt;/P&gt;
&lt;P&gt;2. Check array definition - type out all H_ to test if necessary&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ H_Start    H_End H_1  H_2  H_3  H_4  H_5  H_6  H_7  H_8  H_9  H_10     H_11 H_12;
datalines;
A    3    6    0    1    1    1    1    1    0    1    0    1    1    1
B    2    5    0    1    0    0    0    0    1    1    1    1    1    1
C    9    12   1    1    0    0    0    0    0    0    0    0    0    1
;

data want;
set have;

array _h(*) h_1 - h_12;

do i=h_start to h_end;
 total_sum = sum(total_sum, _h(i));
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Sep 2017 18:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-sum-variables/m-p/395218#M95269</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-12T18:46:03Z</dc:date>
    </item>
  </channel>
</rss>

