<?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: Questions about multidimensional array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349609#M81125</link>
    <description>Yes! Agree! But my school assignment requires us to work with multidimensional array similar to this.&amp;nbsp;/_\&lt;BR /&gt;&lt;BR /&gt;傳送自 Android 上的 Yahoo Mail</description>
    <pubDate>Wed, 12 Apr 2017 20:41:19 GMT</pubDate>
    <dc:creator>Jonathanzz</dc:creator>
    <dc:date>2017-04-12T20:41:19Z</dc:date>
    <item>
      <title>Questions about multidimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349563#M81092</link>
      <description>&lt;P&gt;I want to edit the table using multidimensional array. The codings are&amp;nbsp;below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data dummytable;&lt;/P&gt;&lt;P&gt;input w1 w2 w3 w4;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data ABC;&lt;/P&gt;&lt;P&gt;array w(4,4)_temporary_;&lt;/P&gt;&lt;P&gt;set dummytable;&lt;/P&gt;&lt;P&gt;w(1,2)=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[w(1,2)=1 --&amp;gt; I want to set the second variable&amp;nbsp;of the first observation&amp;nbsp;to 1. However, my code doesn't work.]&lt;/P&gt;&lt;P&gt;I want the table to be look like this:&lt;/P&gt;&lt;P&gt;0 1 0 0&amp;nbsp;&lt;/P&gt;&lt;P&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone tell me how to do it?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 19:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349563#M81092</guid>
      <dc:creator>Jonathanzz</dc:creator>
      <dc:date>2017-04-12T19:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about multidimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349567#M81094</link>
      <description>&lt;P&gt;A 'multidimension' array still only works on a single line at a time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not a good way to implement this in SAS unless you're trying to learn IML which is similar to R or Python.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One&amp;nbsp;way to accomplish your requirements&amp;nbsp;in this case is using the row number with the automatic variable (_N_) and then code w2 directly. You could create an array for that part if desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set dummytable;

array w(4) w1-w4;

if _n_=2  then w(2) = 1;

*if _n_ = 2 then w2=1; *Equivalent code but doesn't need array statement;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138855"&gt;@Jonathanzz&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I want to edit the table using multidimensional array. The codings are&amp;nbsp;below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data dummytable;&lt;/P&gt;
&lt;P&gt;input w1 w2 w3 w4;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;0 0 0 0&lt;/P&gt;
&lt;P&gt;0 0 0 0&lt;/P&gt;
&lt;P&gt;0 0 0 0&lt;/P&gt;
&lt;P&gt;0 0 0 0&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data ABC;&lt;/P&gt;
&lt;P&gt;array w(4,4)_temporary_;&lt;/P&gt;
&lt;P&gt;set dummytable;&lt;/P&gt;
&lt;P&gt;w(1,2)=1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[w(1,2)=1 --&amp;gt; I want to set the second variable&amp;nbsp;of the first observation&amp;nbsp;to 1. However, my code doesn't work.]&lt;/P&gt;
&lt;P&gt;I want the table to be look like this:&lt;/P&gt;
&lt;P&gt;0 1 0 0&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0 0 0 0&lt;/P&gt;
&lt;P&gt;0 0 0 0&lt;/P&gt;
&lt;P&gt;0 0 0 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone tell me how to do it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 19:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349567#M81094</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-12T19:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about multidimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349579#M81103</link>
      <description>&lt;P&gt;Hi, Your approach is almost right, but you didn't frame the array statement into multidimension table at compile time. I like the way you are learning though. Here is your solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data dummytable;&lt;BR /&gt;input w1 w2 w3 w4;&lt;BR /&gt;cards;&lt;BR /&gt;0 0 0 0&lt;BR /&gt;0 0 0 0&lt;BR /&gt;0 0 0 0&lt;BR /&gt;0 0 0 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/*solution*/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data abc;&lt;BR /&gt;set dummytable;&lt;BR /&gt;array w(2,2) w1 w2 w3 w4;&lt;BR /&gt;if _n_=1 then w(1,2)=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 19:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349579#M81103</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-04-12T19:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about multidimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349587#M81108</link>
      <description>&lt;P&gt;Good solution! Thanks a lot for your help! But I have further questions want to ask.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If I also want to edit w(3,3)=1&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;0 0 0 0&lt;BR /&gt;0 0 0 0&lt;BR /&gt;0 0 1 0&lt;BR /&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Or w(4,4)=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;0 0 0 0&lt;/P&gt;&lt;P&gt;0 0 0 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should I do it?&lt;/P&gt;&lt;P&gt;They will out of range went the array is w(2,2).&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 20:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349587#M81108</guid>
      <dc:creator>Jonathanzz</dc:creator>
      <dc:date>2017-04-12T20:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about multidimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349594#M81113</link>
      <description>&lt;P&gt;No, won't go out of range--&amp;gt;&lt;/P&gt;&lt;P&gt;Data dummytable;&lt;BR /&gt;input w1 w2 w3 w4;&lt;BR /&gt;cards;&lt;BR /&gt;0 0 0 0&lt;BR /&gt;0 0 0 0&lt;BR /&gt;0 0 0 0&lt;BR /&gt;0 0 0 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* Your additional needs*/&lt;/P&gt;&lt;P&gt;data abc;&lt;BR /&gt;set dummytable;&lt;BR /&gt;array w(2,2) w1 w2 w3 w4;&lt;BR /&gt;if _n_=1 then w(1,2)=1;&lt;BR /&gt;else if _n_=3 then w(2,1)=1;&lt;BR /&gt;else if _n_=4 then w(2,2)=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Happy now? lol&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 20:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349594#M81113</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-04-12T20:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about multidimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349596#M81115</link>
      <description>I am happy now! lol&lt;BR /&gt;Thanks a lot for your help!</description>
      <pubDate>Wed, 12 Apr 2017 20:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349596#M81115</guid>
      <dc:creator>Jonathanzz</dc:creator>
      <dc:date>2017-04-12T20:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about multidimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349601#M81118</link>
      <description>&lt;P&gt;Just to be pedantic there is absolutely no value in doing it this way, except to demonstrate a multidimension array. The multidimension array still only references a single row and a single set of variables. This method would fall under code obfuscation IMO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 20:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349601#M81118</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-12T20:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about multidimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349609#M81125</link>
      <description>Yes! Agree! But my school assignment requires us to work with multidimensional array similar to this.&amp;nbsp;/_\&lt;BR /&gt;&lt;BR /&gt;傳送自 Android 上的 Yahoo Mail</description>
      <pubDate>Wed, 12 Apr 2017 20:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349609#M81125</guid>
      <dc:creator>Jonathanzz</dc:creator>
      <dc:date>2017-04-12T20:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Questions about multidimensional array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349745#M81200</link>
      <description>&lt;PRE&gt;
Data step is not matrix oriented language, so switch into IML  code to make it happen .


Data dummytable;
input w1 w2 w3 w4;
cards;
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
;
run;
 
proc iml;
use dummytable;
read all var _all_ into w[c=vnames];
close;

w[1,2]=1;
print w[c=vnames];

create want from w[c=vnames];
append from w;
close;
run;


&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Apr 2017 12:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Questions-about-multidimensional-array/m-p/349745#M81200</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-13T12:55:37Z</dc:date>
    </item>
  </channel>
</rss>

