<?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: Using Column Values in an Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846784#M334746</link>
    <description>The code is saying z is uninitialized.&lt;BR /&gt;</description>
    <pubDate>Tue, 29 Nov 2022 12:56:54 GMT</pubDate>
    <dc:creator>jmmedina25</dc:creator>
    <dc:date>2022-11-29T12:56:54Z</dc:date>
    <item>
      <title>Using Column Values in an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846613#M334671</link>
      <description>&lt;P&gt;Hi, I need to use the values of a column in one table as the list in an array.&amp;nbsp; Currently I'm using macro variables to list the values I'm searching for, however one of my lists in in an imported excel doc with this format:&lt;/P&gt;
&lt;P&gt;diag_cd (string variable)&lt;/P&gt;
&lt;P&gt;E091&lt;/P&gt;
&lt;P&gt;E307&lt;/P&gt;
&lt;P&gt;E0072&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my current code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let diag_cd0="E099", "E0910";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data notable_dx;&lt;BR /&gt;set claims;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;array diabarray {25} $ diag_cd1 - diag_cd25;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;diab_ind = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;do i = 1 to 25;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if diabarray {i} in: (&amp;amp;diag_cd0.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;then diab_ind = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;drop i;&lt;/SPAN&gt;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to reference another tables values in the array or a way to transform the values in the first table to a list that looks like the macro variable?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 14:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846613#M334671</guid>
      <dc:creator>jmmedina25</dc:creator>
      <dc:date>2022-11-28T14:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using Column Values in an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846616#M334674</link>
      <description>&lt;P&gt;You could read the data set with the values in the first iteration of the data step, before your logic like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data diag;
input diag_cd $;
datalines;
E091
E307
E0072
;

data notable_dx;

set claims;

array diabarray {25} $ diag_cd1 - diag_cd25;

if _N_ = 1 then do;
do idx = 1 by 1 until (z);
set diag end = z;
diabarray[idx] = diag_cd;
end;
end;

/* Your logic here */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2022 13:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846616#M334674</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-29T13:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using Column Values in an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846633#M334676</link>
      <description>&lt;P&gt;As long as the list of values is short enough that it can fit into a single macro variable then PROC SQL is the simplest way to transfer the values of a VARIABLE (what I assume you meant by the word column) in a dataset into a macro variable.&amp;nbsp; So it looks like you have variable named DIAG_CD in some unknown dataset.&amp;nbsp; Let's assume the dataset is named HAVE.&amp;nbsp; This code will create a macro variable named DIAG_CD0 with space delimited list of quoted strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct quote(trim(diag_cd))
  into :diag_cd0 separated by ' '
from have
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then use that macro variable later in your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data notable_dx;
  set claims;
  array diabarray diag_cd1 - diag_cd25;
  do i = 1 to dim(diabarray) until(diab_ind);
     diab_ind=  diabarray[i] in: (&amp;amp;diag_cd0.);
  end;
  drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that in SAS the IN operator allows you to use either spaces or commas to separate values in the list. Macro variables with commas in them are much harder to work with than macro variables with spaces.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 15:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846633#M334676</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-28T15:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Column Values in an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846784#M334746</link>
      <description>The code is saying z is uninitialized.&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Nov 2022 12:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846784#M334746</guid>
      <dc:creator>jmmedina25</dc:creator>
      <dc:date>2022-11-29T12:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using Column Values in an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846792#M334749</link>
      <description>Sorry, just edited the code</description>
      <pubDate>Tue, 29 Nov 2022 13:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846792#M334749</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-29T13:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using Column Values in an Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846796#M334751</link>
      <description>&lt;P&gt;You could use a hash object (note: code is untested):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data diag;
   input diag_cd $;
   datalines;
E091
E307
E0072
;

data notable_dx;
   set claims;

   if _n_ = 1 then do;
      if 0 then set diag;
      declare hash h(dataset: 'diag');
      h.defineKey('diag_cd');
      h.defineDone();
   end;

   array diabarray {25} $ diag_cd1 - diag_cd25;

&amp;nbsp;&amp;nbsp;&amp;nbsp;diab_ind = 0;

   do i = 1 to 25;
      if h.check(key: diabarray[i]) = 0 then do;
         diab_ind = 1;
         leave; /* no need for further checks */
      end;
   end;

   drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2022 13:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Column-Values-in-an-Array/m-p/846796#M334751</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-11-29T13:48:19Z</dc:date>
    </item>
  </channel>
</rss>

