<?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: Why isn't my array working? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328688#M73403</link>
    <description>&lt;P&gt;So really what you want is a 2 dimensional array (19x19) with indicator variables?&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jan 2017 10:34:21 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2017-01-31T10:34:21Z</dc:date>
    <item>
      <title>Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328682#M73398</link>
      <description>&lt;P&gt;Hi SAS users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to multiply two dummy variables together. I get zeros and&amp;nbsp;missing values (.) but no '1', when I know that both dummies have values 0 and 1 and they SHOULD produce some '1'.&lt;/P&gt;&lt;P&gt;data old;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set new;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; INPUT id dummy1 dummy2&amp;nbsp;nyc rdummy1 rdummy2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; DATALINES;&lt;BR /&gt;1&amp;nbsp;1&amp;nbsp;0 0 1&amp;nbsp;0&lt;BR /&gt;2&amp;nbsp;0&amp;nbsp;1 0&amp;nbsp;0&amp;nbsp;0&lt;BR /&gt;3&amp;nbsp;0&amp;nbsp;1&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&lt;BR /&gt;4&amp;nbsp;1&amp;nbsp;0 1&amp;nbsp;1&amp;nbsp;1&lt;BR /&gt;6&amp;nbsp;1&amp;nbsp;0&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&amp;nbsp;&lt;BR /&gt;7&amp;nbsp;0&amp;nbsp;0 0&amp;nbsp;1&amp;nbsp;1&amp;nbsp;&lt;BR /&gt;8&amp;nbsp;0&amp;nbsp;0 1&amp;nbsp;0&amp;nbsp;1&amp;nbsp;&lt;BR /&gt;9&amp;nbsp;1&amp;nbsp;0 1&amp;nbsp;0&amp;nbsp;1&amp;nbsp;&lt;BR /&gt;10&amp;nbsp;1&amp;nbsp;1&amp;nbsp;0&amp;nbsp;1&amp;nbsp;0&lt;BR /&gt;11 1&amp;nbsp;0&amp;nbsp;1&amp;nbsp;0&amp;nbsp;1&lt;BR /&gt;;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;nyc=0;&lt;/P&gt;&lt;P&gt;if location="NEW YORK" then nyc=1;&lt;/P&gt;&lt;P&gt;array dummies [19] dummy1 - dummy19;&lt;/P&gt;&lt;P&gt;array rdummies [19] rdummy1 - rdummy19;&lt;/P&gt;&lt;P&gt;do i=1 to 19;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rdummies[i]=nyc*dummies[i];&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 11:28:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328682#M73398</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-01-31T11:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328684#M73400</link>
      <description>Hi, Change this line it will work,&lt;BR /&gt;rdummies[i]=nyc*dummies[i]&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Tue, 31 Jan 2017 10:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328684#M73400</guid>
      <dc:creator>abhaykumar</dc:creator>
      <dc:date>2017-01-31T10:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328685#M73401</link>
      <description>&lt;P&gt;You are missing a [i] behind dummies in your loop &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;P&gt;If that still does not work, I recommend that you post some sample data in the form of a data step&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:31:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328685#M73401</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-01-31T10:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328687#M73402</link>
      <description>&lt;P&gt;Sorry my message was incorrectly specified. Message edited. The question unfortuntelly remains....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328687#M73402</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-01-31T10:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328688#M73403</link>
      <description>&lt;P&gt;So really what you want is a 2 dimensional array (19x19) with indicator variables?&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328688#M73403</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-01-31T10:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328689#M73404</link>
      <description>&lt;P&gt;Another good example of why you should post test data in the form of a datastep. &amp;nbsp;What does dummies{x} contain? &amp;nbsp;I.e. what is the benefit of duplicating all 19 variables just to get a pos/neg value? &amp;nbsp;If they contain 0 or 1 as you say, then creating 19 more with 1*val is doing nothing other than creating 19 duplicates of what you already have.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328689#M73404</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-31T10:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328691#M73406</link>
      <description>&lt;P&gt;I think so. That might be it. I want to multiply a series of dummy variables (dummy1- dummy19) with another dummy variable (nyc) and store the solution in a third variable (rdummy1-rdummy19).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328691#M73406</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-01-31T10:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328695#M73408</link>
      <description>&lt;P&gt;That wasn't a very helpful comment. At the moment, I don't know how else I would&amp;nbsp;do what I'm doing. I don't know what you mean by pos/negative values, there should only be 0's and 1's.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328695#M73408</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-01-31T10:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328697#M73409</link>
      <description>&lt;P&gt;You haven't shown us what you are doing. &amp;nbsp;I am merely guessing from what you have posted:&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;I get zeros and&amp;nbsp;missing values (.) but no '1', when I know that both dummies have values 0 and 1 and they SHOULD produce some '1'.&lt;/SPAN&gt;"&lt;/P&gt;
&lt;P&gt;So I am assuimng from that you require binary values, either 0 or 1. &amp;nbsp;However we do not know what dummies{x} contains, you haven't supplied any information, so the first part of my question is what does it look like - post some test data - in the form of a datastep - per the guidance on good posting which you will see underneath Post when you post a new question. &amp;nbsp;This helps us see what data you have, what structure it is, and gives us something to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second part of my question is the why of it. &amp;nbsp;From what you post above, you expect a set of 19 variables with 1 or 0, and you multiple a value by 1, which indicates the values probably lie between 0 and 1 anyway, so the question is why duplicate the data you already have in a second set of varaibles. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without knowing what you are doing or working with its very hard to provide a good answer.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 11:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328697#M73409</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-31T11:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328698#M73410</link>
      <description>&lt;P&gt;Ok, now I understand. I edited the message with test data. The nyc variable is binary (has 0's and 1's).&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 11:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328698#M73410</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-01-31T11:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328699#M73411</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/123185"&gt;@GKati&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to multiply two dummy variables together. I get zeros and&amp;nbsp;missing values (.) but no '1', when I know that both dummies have values 0 and 1 and they SHOULD produce some '1'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;FONT face="Courier New"&gt;DATA survey;&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; INPUT id dummy1 dummy2&amp;nbsp;nyc rdummy1 rdummy2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; DATALINES;&lt;BR /&gt;1&amp;nbsp;1&amp;nbsp;0 0 1&amp;nbsp;0&lt;BR /&gt;2&amp;nbsp;0&amp;nbsp;1 0&amp;nbsp;0&amp;nbsp;0&lt;BR /&gt;3&amp;nbsp;0&amp;nbsp;1&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&lt;BR /&gt;4&amp;nbsp;1&amp;nbsp;0 1&amp;nbsp;1&amp;nbsp;1&lt;BR /&gt;6&amp;nbsp;1&amp;nbsp;0&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&amp;nbsp;&lt;BR /&gt;7&amp;nbsp;0&amp;nbsp;0 0&amp;nbsp;1&amp;nbsp;1&amp;nbsp;&lt;BR /&gt;8&amp;nbsp;0&amp;nbsp;0 1&amp;nbsp;0&amp;nbsp;1&amp;nbsp;&lt;BR /&gt;9&amp;nbsp;1&amp;nbsp;0 1&amp;nbsp;0&amp;nbsp;1&amp;nbsp;&lt;BR /&gt;10&amp;nbsp;1&amp;nbsp;1&amp;nbsp;0&amp;nbsp;1&amp;nbsp;0&lt;BR /&gt;11 1&amp;nbsp;0&amp;nbsp;1&amp;nbsp;0&amp;nbsp;1&lt;BR /&gt;;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data old;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set new;&lt;/P&gt;
&lt;P&gt;nyc=0;&lt;/P&gt;
&lt;P&gt;if location="NEW YORK" then nyc=1;&lt;/P&gt;
&lt;P&gt;array dummies [19] dummy1 - dummy19;&lt;/P&gt;
&lt;P&gt;array rdummies [19] rdummy1 - rdummy19;&lt;/P&gt;
&lt;P&gt;do i=1 to 19;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rdummies[i]=nyc*dummies[i];&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your code is absolutely inconsistent. You create dataset "survey", but never use it; instead you try to create dataset "old" from "new".&lt;/P&gt;
&lt;P&gt;Even if you used "survey", it only has variables up to count 2, while your arrays span over 19 counts!&lt;/P&gt;
&lt;P&gt;Please review those issues, and come back with your real code that you tried.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 11:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328699#M73411</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-31T11:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328700#M73412</link>
      <description>&lt;P&gt;Yes, true. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 11:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328700#M73412</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-01-31T11:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328702#M73413</link>
      <description>&lt;P&gt;Thanks, so code like this works:&lt;/P&gt;
&lt;P&gt;Editing now to show that exactly the same happens with a logic gate AND, hence why I questioned the value of creating x new variables, when locig would also result in the same:&lt;/P&gt;
&lt;PRE&gt;data survey (drop=i);&lt;BR /&gt; input id dummy1 dummy2 nyc;&lt;BR /&gt; array dummy{2};&lt;BR /&gt; array rdummy{2} 8;&lt;BR /&gt; array logic{2} 8;&lt;BR /&gt; do i=1 to 2;&lt;BR /&gt;   rdummy{i}=nyc * dummy{i};&lt;BR /&gt;   logic{i}=ifn(nyc and dummy{i},1,0);&lt;BR /&gt; end;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 0 0&lt;BR /&gt;2 0 1 0&lt;BR /&gt;3 0 1 0&lt;BR /&gt;4 1 0 1&lt;BR /&gt;6 1 0 0 &lt;BR /&gt;7 0 0 0&lt;BR /&gt;8 0 0 1 &lt;BR /&gt;9 1 0 1 &lt;BR /&gt;10 1 1 0&lt;BR /&gt;11 1 0 1&lt;BR /&gt;; &lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 11:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/328702#M73413</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-31T11:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/329193#M73606</link>
      <description>&lt;P&gt;Thank you the ifc() seems to work out well. Theoretically these three commands should produce the same results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;rdummy{i}=nyc * dummy{i};&lt;BR /&gt;if dummy{i}=1 &amp;amp; nyc=1 then rdummy{i}&lt;BR /&gt;logic{i}=ifn(nyc and dummy{i},1,0);&lt;/PRE&gt;&lt;P&gt;in a do-loop for i=1 to 19 (remember my dataset has 19 variables not only 2). But in practice the calculations are incomplete for the first two. SAS creates a variable i running from 1 to 19 and rdummy is only calculated for observations where i equals the index of the dummy. Somehow for the ifn() logic statement, the variable i is a constant number (20 in my case) so this problem doesn't occur. This is what I was trying to understand how this works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 19:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/329193#M73606</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-02-01T19:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Why isn't my array working?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/329323#M73660</link>
      <description>&lt;P&gt;If your having difficulty with something, then you will need to post&amp;nbsp;&lt;STRONG&gt;exact and complete&lt;/STRONG&gt; test data which covers the issue. &amp;nbsp;Follow;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't tell anything from what you have posted about the data. &amp;nbsp;There are a couple of typos in what you have posted though:&lt;/P&gt;
&lt;PRE&gt;rdummy{i}=nyc * dummy{i};    If nyc or dummy{i} is missing then multiplication wont work&lt;BR /&gt;if dummy{i}=1 &amp;amp; nyc=1 then rdummy{i}     This doesn't do anything, no assignment, missing semicolon, you &lt;BR /&gt;                                         also drop the =1 from both checks as if 1 is always true.&lt;BR /&gt;logic{i}=ifn(nyc and dummy{i},1,0);&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Feb 2017 09:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-isn-t-my-array-working/m-p/329323#M73660</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-02T09:13:39Z</dc:date>
    </item>
  </channel>
</rss>

