<?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: Array Question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309135#M270692</link>
    <description>&lt;P&gt;Your array has exaclyt one element: Numvar. It only has the value on a current row as the SAS data step processes one row of data at a time. Let's repeat that: SAS data step only sees one row at a time. You have to do extra (some times a lot extra) work to reference values in a different row of the data and sometimes not very practical in a data step at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_ being in effect the row number as soon as you get to the second row the value is 2 and exceeds the size of the array and generates errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to address ROW and COLUMN at the same time for all of the data then you need to move over to PROC IML to deal with matrices.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Nov 2016 19:48:25 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-11-03T19:48:25Z</dc:date>
    <item>
      <title>Array Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309117#M270686</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone tell me why I can't reference some entry in an array with the&amp;nbsp;observation pointer _N_?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;lets sat that I have some dataset and wanted to reference the entry in the array corresponding to the current observation number, what approach should I use?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input CharVar $ Numvar;
datalines;
A 1
B 2
C 3
;
run;

data ArrayTest;
   set have;
   
   Array SomeArray{*} Numvar;
   
   NewVar = SomeArray[_N_];
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The above gives me an error.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 18:52:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309117#M270686</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-03T18:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Array Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309121#M270687</link>
      <description>&lt;P&gt;Your ARRAY does not have enough elements.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 19:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309121#M270687</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-11-03T19:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Array Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309126#M270688</link>
      <description>&lt;P&gt;Doesn't it have three elements? One for each row in the NumVar column?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 19:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309126#M270688</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-03T19:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Array Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309128#M270689</link>
      <description>&lt;P&gt;You probably want to convert your input data into an array.&lt;/P&gt;
&lt;P&gt;you can do it using PROC TRANSPOSE &amp;nbsp;or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;by a datastep like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;retain var1 - &lt;STRONG&gt;var3&lt;/STRONG&gt;;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;array&lt;/STRONG&gt; varx var1-&lt;STRONG&gt;var3&lt;/STRONG&gt; ; &amp;nbsp; &amp;nbsp;/* replace 3 in &lt;STRONG&gt;var3&lt;/STRONG&gt; at least to the expected number of rows or more */&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; CharVar &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; Numvar&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;varx(_N_) = Numvar;&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if charvar = 'Z' then output; &amp;nbsp; &amp;nbsp; /* I added that row to assign end of input */&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;A 1 &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;B 2 &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;C 3&lt;BR /&gt;Z . &lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;/* your HAVE dataset shall have just onw row with &lt;STRONG&gt;n&lt;/STRONG&gt;=max(_N_) ovariables: var1 to var&lt;STRONG&gt;n */&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 19:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309128#M270689</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-03T19:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Array Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309130#M270690</link>
      <description>&lt;P&gt;You are confusing observations(records) and variables.&amp;nbsp; What are you trying to do?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 19:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309130#M270690</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-11-03T19:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Array Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309132#M270691</link>
      <description>what did you meant by&lt;BR /&gt;Array SomeArray{*} Numvar;</description>
      <pubDate>Thu, 03 Nov 2016 19:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309132#M270691</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-03T19:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Array Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309135#M270692</link>
      <description>&lt;P&gt;Your array has exaclyt one element: Numvar. It only has the value on a current row as the SAS data step processes one row of data at a time. Let's repeat that: SAS data step only sees one row at a time. You have to do extra (some times a lot extra) work to reference values in a different row of the data and sometimes not very practical in a data step at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_ being in effect the row number as soon as you get to the second row the value is 2 and exceeds the size of the array and generates errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to address ROW and COLUMN at the same time for all of the data then you need to move over to PROC IML to deal with matrices.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 19:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309135#M270692</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-03T19:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Array Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309140#M270693</link>
      <description>&lt;P&gt;Thank you all &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; This makes sense.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 20:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Question/m-p/309140#M270693</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-03T20:05:44Z</dc:date>
    </item>
  </channel>
</rss>

