<?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/713601#M220174</link>
    <description>&lt;P&gt;Why are there 5 columns after ID in tables 2a and 2b, but only four different codes shown in table 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do we know the complete list of codes that can appear? Or do we have to figure that out from the data?&lt;/P&gt;</description>
    <pubDate>Sat, 23 Jan 2021 15:57:16 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-01-23T15:57:16Z</dc:date>
    <item>
      <title>Arrays?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/713598#M220173</link>
      <description>&lt;P&gt;In the data I have, exists the following -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Rule_1&lt;/TD&gt;&lt;TD&gt;Rule_2&lt;/TD&gt;&lt;TD&gt;Rule_3&lt;/TD&gt;&lt;TD&gt;Rule_4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0001&lt;/TD&gt;&lt;TD&gt;PCODE_27&lt;/TD&gt;&lt;TD&gt;RCODE_1&lt;/TD&gt;&lt;TD&gt;RCODE_2&lt;/TD&gt;&lt;TD&gt;OCODE_1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0002&lt;/TD&gt;&lt;TD&gt;RCODE_2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the task of validating that the codes being returned are correct and this had led me to produce data which looks like this;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 2a&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;PCODE_27&lt;/TD&gt;&lt;TD&gt;RCODE_1&lt;/TD&gt;&lt;TD&gt;RCODE_2&lt;/TD&gt;&lt;TD&gt;OCODE_1&lt;/TD&gt;&lt;TD&gt;RCODE_21&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0001&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0002&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'1' would indicate that rule was correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create an array which would be populated for each record but only where the value is 1. My expectation is that it would end up looking something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 2b&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;EXP_CODE_1&lt;/TD&gt;&lt;TD&gt;EXP_CODE_2&lt;/TD&gt;&lt;TD&gt;EXP_CODE_3&lt;/TD&gt;&lt;TD&gt;EXP_CODE_4&lt;/TD&gt;&lt;TD&gt;EXP_CODE_5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0001&lt;/TD&gt;&lt;TD&gt;PCODE_27&lt;/TD&gt;&lt;TD&gt;RCODE_1&lt;/TD&gt;&lt;TD&gt;RCODE_2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0002&lt;/TD&gt;&lt;TD&gt;RCODE_2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This would then allow me to compare tables 1 and 2b directly&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like your advice as to whether I am correct in my approach and if so how would I go about creating the array&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 14:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/713598#M220173</guid>
      <dc:creator>twenty7</dc:creator>
      <dc:date>2021-01-23T14:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/713601#M220174</link>
      <description>&lt;P&gt;Why are there 5 columns after ID in tables 2a and 2b, but only four different codes shown in table 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do we know the complete list of codes that can appear? Or do we have to figure that out from the data?&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 15:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/713601#M220174</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-23T15:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/713606#M220177</link>
      <description>&lt;P&gt;there can be unto 99 different codes that can appear and we do know the full list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the reason for the different columns was to highlight there could be rules which have not triggered yet in the data available&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2021 17:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/713606#M220177</guid>
      <dc:creator>twenty7</dc:creator>
      <dc:date>2021-01-23T17:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/713607#M220178</link>
      <description>&lt;P&gt;Data as text is good, but it is easier to reply if you post your data as datasets.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one ;
  input (id Rule_1-Rule_4) ($);
cards;
0001 PCODE_27 RCODE_1 RCODE_2 OCODE_1
0002 RCODE_2  .       .       .
;

data two;
  input ID $ PCODE_27 RCODE_1 RCODE_2 OCODE_1 RCODE_21;
cards;
0001 1 1 1 0 0
0002 0 0 1 0 0
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You should be able to test directly by merging the two datasets.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;
   merge one two;
   by id ;
   array rules rule_: ;
   do index=1 to dim(rules);
     if rules[index] ne ' ' then do;
       if strip(vvaluex(rules[index])) ne '1' then put 'Rule not satisfied. ' id= rules[index]= ;
     end;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Rule not satisfied. id=0001 Rule_4=OCODE_1
&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Jan 2021 18:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/713607#M220178</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-23T18:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/714020#M220369</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did make a slight amendment to output the result into a new column&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;
   merge one two;
   by id ;
   array rules rule_: ;
   do index=1 to dim(rules);
     if rules[index] ne ' ' then do;
       if rules_match = "" and strip(vvaluex(rules[index])) ne 1 then rules_match = "differences"
     end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This would allow the user to easily isolate records where there is not a 100% match&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would the reverse of this work where I need to identify records where there is a 1 but the code is not present in the array that is defined in the code above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 19:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/714020#M220369</guid>
      <dc:creator>twenty7</dc:creator>
      <dc:date>2021-01-25T19:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/714037#M220376</link>
      <description>&lt;P&gt;Why not just create a dataset that has the rule and the result in the same observation?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   merge one two;
   by id ;
   array rules rule_: ;
   do index=1 to dim(rules);
     RULE = rules[index] ;
     if rule ne ' ' then do;
       RESULT=input(strip(vvaluex(rule)),1.);
       output;
     end;
  end;
  keep id RULE RESULT;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jan 2021 19:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays/m-p/714037#M220376</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-25T19:34:31Z</dc:date>
    </item>
  </channel>
</rss>

