<?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 How to use arrays: confused about arrays in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-arrays-confused-about-arrays/m-p/579911#M13496</link>
    <description>&lt;P&gt;I want to use arrays but confused on how to create and use it.&amp;nbsp; While reading about arrays, I came across this explanation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array newvars [3] test1-test3 (45 23 21);&lt;/P&gt;&lt;P&gt;newvars[3] will return 21&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;while I get that newvars[3] returns 21, what I don't get is test1-test3. what are they for? it's not even needed since I can get the value from the array by referencing it, e.g. newvars[2].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;more importantly, I am working on this logic:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create an array of strings and use that array inside a do loop.&amp;nbsp; please help me create the array.&amp;nbsp; Here's my initial stab at it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array oldarray[4] ('word1' 'two words' 'more words' 'still more words'); &amp;nbsp; /* i don't need variables */&lt;/P&gt;&lt;P&gt;do i = 1 to 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *use oldarray[i] here to manipulate a variable;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please help.&amp;nbsp; I only need how to create the array.&lt;/P&gt;</description>
    <pubDate>Thu, 08 Aug 2019 15:28:31 GMT</pubDate>
    <dc:creator>jffeudo86</dc:creator>
    <dc:date>2019-08-08T15:28:31Z</dc:date>
    <item>
      <title>How to use arrays: confused about arrays</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-arrays-confused-about-arrays/m-p/579911#M13496</link>
      <description>&lt;P&gt;I want to use arrays but confused on how to create and use it.&amp;nbsp; While reading about arrays, I came across this explanation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array newvars [3] test1-test3 (45 23 21);&lt;/P&gt;&lt;P&gt;newvars[3] will return 21&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;while I get that newvars[3] returns 21, what I don't get is test1-test3. what are they for? it's not even needed since I can get the value from the array by referencing it, e.g. newvars[2].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;more importantly, I am working on this logic:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create an array of strings and use that array inside a do loop.&amp;nbsp; please help me create the array.&amp;nbsp; Here's my initial stab at it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array oldarray[4] ('word1' 'two words' 'more words' 'still more words'); &amp;nbsp; /* i don't need variables */&lt;/P&gt;&lt;P&gt;do i = 1 to 4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *use oldarray[i] here to manipulate a variable;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please help.&amp;nbsp; I only need how to create the array.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 15:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-arrays-confused-about-arrays/m-p/579911#M13496</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-08-08T15:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to use arrays: confused about arrays</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-arrays-confused-about-arrays/m-p/579918#M13497</link>
      <description>&lt;P&gt;To create an array without variables, use the keyword _TEMPORARY_:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array oldarray[4] $ 20 _temporary_ ('word1' 'two words' 'more words' 'still more words'); &amp;nbsp; /* i don't need variables */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note that array elements must be defined as numeric or character, or else they will default to numeric.&amp;nbsp; In the case of a _temporary_ array, there may be some flexibility there, but I can't test it right now.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also note, elements within a _temporary_ array maintain their values from one observation to the next.&amp;nbsp; If you want them to start over from some baseline set of values on every observations, you need to re-set them.&amp;nbsp; Any changes you make stay changed as you move from one observation to the next.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 15:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-arrays-confused-about-arrays/m-p/579918#M13497</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-08-08T15:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use arrays: confused about arrays</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-arrays-confused-about-arrays/m-p/579921#M13498</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271494"&gt;@jffeudo86&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to use arrays but confused on how to create and use it.&amp;nbsp; While reading about arrays, I came across this explanation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array newvars [3] test1-test3 (45 23 21);&lt;/P&gt;
&lt;P&gt;newvars[3] will return 21&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;while I get that newvars[3] returns 21, what I don't get is test1-test3. what are they for? it's not even needed since I can get the value from the array by referencing it, e.g. newvars[2].&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;more importantly, I am working on this logic:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create an array of strings and use that array inside a do loop.&amp;nbsp; please help me create the array.&amp;nbsp; Here's my initial stab at it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array oldarray[4] ('word1' 'two words' 'more words' 'still more words'); &amp;nbsp; /* i don't need variables */&lt;/P&gt;
&lt;P&gt;do i = 1 to 4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *use oldarray[i] here to manipulate a variable;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please help.&amp;nbsp; I only need how to create the array.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There are several ways to use an array. One is to use an array to &lt;STRONG&gt;create&lt;/STRONG&gt; new variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array a {5} ;&lt;/P&gt;
&lt;P&gt;will create numeric variables A1, A2, A3, A4, A5.&lt;/P&gt;
&lt;P&gt;Array a{3} test1-test3 ; may do one of two things that depend on the current data set. If the Variables test1, test2 and test 3 already exist in the data then you can use array shorthand a[1] to refer to the existing variable Test1. If the variables to not currently exist then the array statement creates them and you can reference them with the array shorthand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;array oldarray[4] ('word1' 'two words' 'more words' 'still more words');   /* i don't need variables */&lt;/PRE&gt;
&lt;P&gt;with strings you need more work, first you need to tell SAS the values are character and how long they will be&lt;/P&gt;
&lt;P&gt;Array oldarray{4} $ 25 for example to tell SAS that the values may be up to 25 characters.&lt;/P&gt;
&lt;P&gt;If you don't want the variables in the output data set you can create a temporary array:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;  array oldarray[4] $ 25 _temporary_ ('word1' 'two words' 'more words' 'still more words');
&lt;/PRE&gt;
&lt;P&gt;Note that _temporary_ arrays values persist across data step record boundaries. So be careful about assigning values to the array elements as you may have unintended consequences.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 15:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-arrays-confused-about-arrays/m-p/579921#M13498</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-08T15:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to use arrays: confused about arrays</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-arrays-confused-about-arrays/m-p/579927#M13499</link>
      <description>Thank you! You explained it well.</description>
      <pubDate>Thu, 08 Aug 2019 16:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-arrays-confused-about-arrays/m-p/579927#M13499</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-08-08T16:09:25Z</dc:date>
    </item>
  </channel>
</rss>

