<?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: array using a list in another data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492387#M129389</link>
    <description>&lt;P&gt;If your data was in a long format then yes, this would be trivial. It's probably easiest to transpose your data and use that method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to stay vertical, you can load your second data set into a temporary array and use that. You would likely want to have two nested loops, looping of all the conditions and all of the diagnosis, or use WHICHC.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's a basic example of a temporary array here and loading it from a data set:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/f052b5223fecca066b1f" target="_blank"&gt;https://gist.github.com/statgeek/f052b5223fecca066b1f&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not a really great example but hopefully gives you the idea of how to load the data set and use it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Sep 2018 17:16:46 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-09-04T17:16:46Z</dc:date>
    <item>
      <title>array using a list in another data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492375#M129382</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have the following code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data&amp;nbsp;a (drop=i);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array x{*} dx:;&lt;/P&gt;&lt;P&gt;vcf2=0;&lt;/P&gt;&lt;P&gt;do i=1 to dim(x);&lt;/P&gt;&lt;P&gt;vcf2= ifn(substrn(x{i},1,5)in ( **),1,vcf2);&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;P&gt;Is there a way to put instead of the start a long list of numbers that are in another subset of data? so for example&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;vcf2= ifn(substrn(x{i},1,5)in (&amp;nbsp; variable c in work.c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;),1,vcf2);&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 16:53:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492375#M129382</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-09-04T16:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: array using a list in another data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492387#M129389</link>
      <description>&lt;P&gt;If your data was in a long format then yes, this would be trivial. It's probably easiest to transpose your data and use that method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to stay vertical, you can load your second data set into a temporary array and use that. You would likely want to have two nested loops, looping of all the conditions and all of the diagnosis, or use WHICHC.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's a basic example of a temporary array here and loading it from a data set:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/f052b5223fecca066b1f" target="_blank"&gt;https://gist.github.com/statgeek/f052b5223fecca066b1f&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not a really great example but hopefully gives you the idea of how to load the data set and use it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 17:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492387#M129389</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-04T17:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: array using a list in another data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492389#M129390</link>
      <description>&lt;P&gt;You can't mix and match DATA step code and SQL code. In a DATA step, you can only use DATA step code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;vcf2= ifn(substrn(x{i},1,5) in ('horse','sheep','robin'),1,vcf2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but of course this requires a lot of typing and avoiding making typing errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values are stored in a data set (in other words, you have a data set with a column named NAME, and the value in row 1 is horse and the value in row 2 is sheep and so on, then you could create a macro variable named &amp;amp;names that contains the list you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mylistdataset;
    input name $;
cards;
horse
sheep
robin
;

proc sql noprint;
    select distinct quote(trim(name)) into :names separated by ',' from mylistdataset;
quit;

data a (drop=i);
    set b;
    array x{*} dx:;
    vcf2=0;
    do i=1 to dim(x);
        vcf2= ifn(substrn(x{i},1,5)in (&amp;amp;names),1,vcf2);
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Sep 2018 17:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492389#M129390</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-09-04T17:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: array using a list in another data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492393#M129392</link>
      <description>&lt;P&gt;Thank you Reeza and Paige, yes the value is stored in a dataset because it includes a list of 1000+ numbers.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 17:37:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492393#M129392</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-09-04T17:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: array using a list in another data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492395#M129394</link>
      <description>&lt;P&gt;Macro variables have a limit of ~65k characters. So you're 1000 numbers need to be less than 6 characters each, not including the , and quotation marks which may be an issue for you. Make sure to verify that the macro variable is created correctly.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72105"&gt;@lillymaginta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you Reeza and Paige, yes the value is stored in a dataset because it includes a list of 1000+ numbers.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 17:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492395#M129394</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-04T17:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: array using a list in another data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492399#M129396</link>
      <description>&lt;P&gt;So the macro variable created would have 5 digit text, quotes on either side and a comma following, that's 8 characters, so the size limit for macro variables would not be exceeded unless the list had over 8000 items. If that did happen, you could either split the macro variable into pieces, each piece being less than 65K characters, or you could use CALL EXECUTE.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 18:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-using-a-list-in-another-data/m-p/492399#M129396</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-09-04T18:01:19Z</dc:date>
    </item>
  </channel>
</rss>

