<?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: arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/arrays/m-p/345940#M79664</link>
    <description>&lt;P&gt;What are you trying to do? Specifically, given your example, what do you want the resulting file to look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
    <pubDate>Thu, 30 Mar 2017 19:39:49 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-03-30T19:39:49Z</dc:date>
    <item>
      <title>arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays/m-p/345935#M79662</link>
      <description>&lt;P&gt;I have &amp;nbsp;the following data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test1;
	input sal hike;
	cards;
1000 2000
2000 3000
3000 4000
4000 5000
;
run;

data test2;
	set test1;
	array q1[1] sal;
	array q2[1] hike;
	array q3[1];

	do i=1 to 4;
		q3[i]=q1[i]-q2[i];
	end;
run;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;I am gettng the following error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;216 data test1;&lt;BR /&gt;217 input sal hike;&lt;BR /&gt;218 cards;&lt;/P&gt;
&lt;P&gt;NOTE: The data set WORK.TEST1 has 4 observations and 2 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;223 ;&lt;BR /&gt;224 run;&lt;BR /&gt;225 data test2;&lt;BR /&gt;226 set test1;&lt;BR /&gt;227 array q1[1] sal ;&lt;BR /&gt;228 array q2[1] hike;&lt;BR /&gt;229 array q3[1];&lt;BR /&gt;230 do i=1 to 4;&lt;BR /&gt;231 q3[i]=q1[i]-q2[i];&lt;BR /&gt;232 end;&lt;BR /&gt;233 run;&lt;/P&gt;
&lt;P&gt;ERROR: Array subscript out of range at line 231 column 13.&lt;BR /&gt;sal=1000 hike=2000 q31=-1000 i=2 _ERROR_=1 _N_=1&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: There were 1 observations read from the data set WORK.TEST1.&lt;BR /&gt;WARNING: The data set WORK.TEST2 may be incomplete. When this step was stopped there were 0&lt;BR /&gt;observations and 4 variables.&lt;BR /&gt;WARNING: Data set WORK.TEST2 was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 19:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays/m-p/345935#M79662</guid>
      <dc:creator>molla</dc:creator>
      <dc:date>2017-03-30T19:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays/m-p/345940#M79664</link>
      <description>&lt;P&gt;What are you trying to do? Specifically, given your example, what do you want the resulting file to look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 19:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays/m-p/345940#M79664</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-30T19:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays/m-p/345942#M79666</link>
      <description>&lt;P&gt;The proximate cause of the error you see is that your arrays Q1 and Q2 only have one element each.&amp;nbsp; So when i=2 in your loop there is no second, third or fourth element to address.&lt;/P&gt;
&lt;P&gt;Arrays operate within rows of data not across observations which is what appears you want to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want:&lt;/P&gt;
&lt;P&gt;data test2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set test1;&lt;BR /&gt;&amp;nbsp; q3 = sal - hire;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;if your goal is to get the difference of sal and hire for each pair. There would be a new variable to hold the value on each data row.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 19:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays/m-p/345942#M79666</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-30T19:44:40Z</dc:date>
    </item>
  </channel>
</rss>

