<?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/374667#M89741</link>
    <description>I want to multiply those 4 values to every 1-4 observations repeatedly .&lt;BR /&gt;&lt;BR /&gt;like Donald will multiply by 1st value of array&lt;BR /&gt;then Ricky by 2nd value of array ..&lt;BR /&gt;&lt;BR /&gt;This operation repeat for every 1-4 observation.&lt;BR /&gt;&lt;BR /&gt;I am sorry if am unable to portray what i want</description>
    <pubDate>Mon, 10 Jul 2017 19:21:59 GMT</pubDate>
    <dc:creator>shivamarrora0</dc:creator>
    <dc:date>2017-07-10T19:21:59Z</dc:date>
    <item>
      <title>Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374643#M89726</link>
      <description>&lt;P&gt;Hi All, i want to use array and loops only&lt;/P&gt;&lt;P&gt;i want to multiply the 1st emp salary by .10 2nd by .25 3rd by .09 and 4th by .11&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input emp_name $ sal ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;Kevin 3000&lt;/P&gt;&lt;P&gt;david 2300&lt;/P&gt;&lt;P&gt;Kat 2100&lt;/P&gt;&lt;P&gt;ricky 10000 ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 18:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374643#M89726</guid>
      <dc:creator>shivamarrora0</dc:creator>
      <dc:date>2017-07-10T18:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374650#M89731</link>
      <description>&lt;PRE&gt;data have (drop=mult:);
  input emp_name $ sal ;
  array mult(4) (.1,.25,.09,.11);
  want=sal*mult(_n_);
  cards;
Kevin 3000
david 2300
Kat 2100
ricky 10000
;
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, 10 Jul 2017 18:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374650#M89731</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-10T18:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374658#M89735</link>
      <description>but if i have some more observations and want to multiply them by same , then it will give the error " Array subscript out of range"&lt;BR /&gt;&lt;BR /&gt;ex:&lt;BR /&gt;&lt;BR /&gt;data have (drop=mult:);&lt;BR /&gt;input emp_name $ sal ;&lt;BR /&gt;array mult(4) (.1,.25,.09,.11);&lt;BR /&gt;want=sal*mult(_n_);&lt;BR /&gt;cards;&lt;BR /&gt;Kevin 3000&lt;BR /&gt;david 2300&lt;BR /&gt;Kat 2100&lt;BR /&gt;ricky 10000&lt;BR /&gt;Donald 2100&lt;BR /&gt;Ricky 1100&lt;BR /&gt;;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 10 Jul 2017 19:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374658#M89735</guid>
      <dc:creator>shivamarrora0</dc:creator>
      <dc:date>2017-07-10T19:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374661#M89738</link>
      <description>&lt;P&gt;Not sure how you want to apply the multipliers. Something like the following?:&lt;/P&gt;
&lt;PRE&gt;data have (drop=mult:);
  input emp_name $ sal ;
  array mult(0:3) (.11,.1,.25,.09);
  want=sal*mult(mod(_n_,4));
  cards;
Kevin 3000
david 2300
Kat 2100
ricky 10000
Donald 2100
Ricky 1100
;
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, 10 Jul 2017 19:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374661#M89738</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-10T19:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374665#M89740</link>
      <description>&lt;P&gt;This problem isn't conducive to arrays or loops especially if you need to extend it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure why you want to go down that route, but it's exactly the wrong approach in SAS.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post a better example of what you're looking to accomplish here.&lt;/P&gt;
&lt;P&gt;If this is a learning exercise, well, to learn it, you need to write the code anyways &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&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/144247"&gt;@shivamarrora0&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi All, i want to use array and loops only&lt;/P&gt;
&lt;P&gt;i want to multiply the 1st emp salary by .10 2nd by .25 3rd by .09 and 4th by .11&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;input emp_name $ sal ;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;Kevin 3000&lt;/P&gt;
&lt;P&gt;david 2300&lt;/P&gt;
&lt;P&gt;Kat 2100&lt;/P&gt;
&lt;P&gt;ricky 10000 ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374665#M89740</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-10T19:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374667#M89741</link>
      <description>I want to multiply those 4 values to every 1-4 observations repeatedly .&lt;BR /&gt;&lt;BR /&gt;like Donald will multiply by 1st value of array&lt;BR /&gt;then Ricky by 2nd value of array ..&lt;BR /&gt;&lt;BR /&gt;This operation repeat for every 1-4 observation.&lt;BR /&gt;&lt;BR /&gt;I am sorry if am unable to portray what i want</description>
      <pubDate>Mon, 10 Jul 2017 19:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374667#M89741</guid>
      <dc:creator>shivamarrora0</dc:creator>
      <dc:date>2017-07-10T19:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374670#M89742</link>
      <description>&lt;P&gt;That is what the code I posted accomplished. Again it was:&lt;/P&gt;
&lt;PRE&gt;data have (drop=mult:);
  input emp_name $ sal ;
  array mult(0:3) (.11,.1,.25,.09);
  want=sal*mult(mod(_n_,4));
  cards;
Kevin 3000
david 2300
Kat 2100
ricky 10000
Donald 2100
Ricky 1100
;
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, 10 Jul 2017 19:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374670#M89742</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-10T19:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374672#M89743</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/144247"&gt;@shivamarrora0&lt;/a&gt; wrote:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I am sorry if am unable to portray what i want&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you can't define your problem you can't solve it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS loops through rows by default and there's a row counter variable _n_ which will work in this situation. The MOD() function will create counters from 1 to 4 or you could do a manual count. Use that variable as an index the array of the ratios. If you have more ratios you can load the temporary array from a dataset rather than type it out. I'll leave that for another day. I've separated the steps to make it more clear below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have (drop=mult:);
	input emp_name $ sal;
	cards;
Kevin 3000
david 2300
Kat 2100
ricky 10000
Fred 100
Betty 2000
Shiva 0
Random .
Check 23
;
run;

data want;
	set have;
	array mult(4) _temporary_ (0.1, 0.25, 0.09, 0.11); *array with rates;
	index=mod(_n_-1, 4)+1; *calculate which value from the array you need;
	value=mult(index)*sal; *multiple the value in SAL by the respective value in the array;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374672#M89743</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-10T19:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374675#M89744</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;Mod() starts at 1, not 0 though, and you've indexed the array to 0-3 so it's going to be off by 1? Or am I missing something?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374675#M89744</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-10T19:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374676#M89745</link>
      <description>&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10233i5B08F68F75FEA09D/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="sas.PNG" title="sas.PNG" /&gt;&lt;/P&gt;&lt;P&gt;i want this as output&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:36:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374676#M89745</guid>
      <dc:creator>shivamarrora0</dc:creator>
      <dc:date>2017-07-10T19:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374681#M89747</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374681#M89747</guid>
      <dc:creator>shivamarrora0</dc:creator>
      <dc:date>2017-07-10T19:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374686#M89748</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;: You were missing something. Mod4 of 1=1, mod4 of 2=2, mod4 of 3=3 and mod4 of 4 =0. As such, I simply used an array ranging from 0 to 3, putting the fourth value first, followed by the other three values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code ends up accomplishing the same thing, but requires 3&amp;nbsp;additional calculations (_n_-1, +1 and index) which weren't needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 20:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374686#M89748</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-10T20:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374690#M89749</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;: You were missing something. Mod4 of 1=1, mod4 of 2=2, mod4 of 3=3 and mod4 of 4 =0. As such, I simply used an array ranging from 0 to 4, putting the fourth value first, followed by the other three values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code ends up accomplishing the same thing, but requires 3&amp;nbsp;additional calculations (_n_-1, +1 and index) which weren't needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Neat, thanks for the explanation!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 20:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/374690#M89749</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-10T20:06:47Z</dc:date>
    </item>
  </channel>
</rss>

