<?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 Question_missing numeric suffix on a numbered variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355068#M83149</link>
    <description>&lt;P&gt;You should define:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;array want {12} want1-want12;&lt;/STRONG&gt; &amp;nbsp;Not just &lt;STRONG&gt;array want {12}&lt;/STRONG&gt;;&lt;/P&gt;</description>
    <pubDate>Mon, 01 May 2017 20:43:04 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-05-01T20:43:04Z</dc:date>
    <item>
      <title>Do Loop Question_missing numeric suffix on a numbered variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355060#M83144</link>
      <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a problem running the following programs, the log screen gives me the following error message:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Missing numeric suffix on a numbered variable list (p1-p).&lt;/P&gt;
&lt;P&gt;ERROR: Undeclared array referenced: NAME.&lt;/P&gt;
&lt;P&gt;ERROR: Variable NAME has not been declared as an array.&lt;/P&gt;
&lt;P&gt;ERROR 22-322: Expecting a name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My purpose is to aggregate purchase amount. So it would be something like:&lt;/P&gt;
&lt;P&gt;want1=prchs1;&lt;/P&gt;
&lt;P&gt;want2=prchs1+prchs2;&lt;/P&gt;
&lt;P&gt;want3=prchs1+prchs2+prchs3;&lt;/P&gt;
&lt;P&gt;.............&lt;/P&gt;
&lt;P&gt;Could&amp;nbsp;anyone please let me know what's wrong with&amp;nbsp;my syntax below&amp;nbsp;or any other suggested way to achieve my goal? Thanks in advance!&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;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want{&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;};&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;array p{12} prchs1-prchs12;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;want[i]=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;want[i] = sum(of p1 - p[i]);&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 20:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355060#M83144</guid>
      <dc:creator>zhige50</dc:creator>
      <dc:date>2017-05-01T20:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop Question_missing numeric suffix on a numbered variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355064#M83146</link>
      <description>&lt;P&gt;What you want is not possible.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want[i] = sum(of p1 - p[i]);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are mixing a compile time concept (the variable list) with a run time concetp (an array reference).&lt;/P&gt;
&lt;P&gt;It actually is easy with this formula.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array want (12);
array p prchs1-prchs12;
want(1) = sum(0,p(1));
do i=2 to dim(p);
  want(i)=sum(want(i-1),p(i));
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 20:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355064#M83146</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-01T20:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop Question_missing numeric suffix on a numbered variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355065#M83147</link>
      <description>&lt;P&gt;The problem arises in referring to p[i] as part of a variable list.&amp;nbsp; SAS requires the name to be hard-coded, rather than an indirect reference (when used as part of a variable list).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a relatively easy problem to overcome.&amp;nbsp; For example, you could try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want1 = prchs1;&lt;/P&gt;
&lt;P&gt;do i=2 to 12;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; want{i} = want{i-1} + p{i};&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 20:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355065#M83147</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-01T20:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop Question_missing numeric suffix on a numbered variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355068#M83149</link>
      <description>&lt;P&gt;You should define:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;array want {12} want1-want12;&lt;/STRONG&gt; &amp;nbsp;Not just &lt;STRONG&gt;array want {12}&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 20:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355068#M83149</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-05-01T20:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop Question_missing numeric suffix on a numbered variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355070#M83150</link>
      <description>&lt;P&gt;I would do it as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input prchs1-prchs12;
  cards;
1 2 3 4 5 6 7 8 9 0 1 2
2 3 4 5 6 7 8 9 0 1 2 3
;

data want;
  set have;
  array want{12};
  array p{12} prchs1-prchs12;
  array s{12};
  do i=1 to 12;
    want[i]=0;
    s(i)=p(i);
    want[i] = sum(of s(*));
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 20:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Question-missing-numeric-suffix-on-a-numbered-variable/m-p/355070#M83150</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-01T20:46:09Z</dc:date>
    </item>
  </channel>
</rss>

