<?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: How can I search a range of columns for if any one of them starts with a particular string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683404#M206991</link>
    <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;INDICATOR=prxmatch('/:(345|817|I37)/', ':'||catx(':',of CODE_0-CODE_5))&amp;gt;0;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 12 Sep 2020 04:30:37 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-09-12T04:30:37Z</dc:date>
    <item>
      <title>How can I search a range of columns for if any one of them starts with a particular string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683381#M206982</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create an indicator at the row level for if a series of codes appears in a range of columns.&lt;/P&gt;&lt;P&gt;The logic should be:&lt;/P&gt;&lt;P&gt;If any of columns code_0-code_n have values starting with '345', '817' or 'I37' &amp;nbsp;indicator=1, else indicator=0.&lt;/P&gt;&lt;P&gt;It's important that it is "starts with" rather than contains, because I do not want codes like "G345" to be counted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a small version of what the data looks like--in reality it is up to 24 codes.&lt;/P&gt;&lt;PRE&gt; data WORK.IMPORT;
   infile datalines dsd truncover;
   input person:$4. code_0:$4. code_1:$4. code_2:$4. code_3:$4. code_4:$4. code_5:$4.;
 datalines;
 Jane 345 I371 693 1125 G260 2461
 Jake G345 8170 565 8172 8701 2717
 Joan 890 8172 653 C980 3652 I370
 Mark 410 149 K628 3450 229 S280
 Mary 2797 D140 P635 1025 445 O980
 ;;;;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm relatively new to SAS--I tried with this array, but it seemed to only count if the last code began with those strings:&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array icd code_0-code_5;
do i = 1 to dim(icd);
if icd[i]=:'345' or icd[i]=:'817' or icd[i]=:'I37' the indicator=1;
else indicator=0;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;Thanks in advance for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 00:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683381#M206982</guid>
      <dc:creator>ESpiel</dc:creator>
      <dc:date>2020-09-12T00:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I search a range of columns for if any one of them starts with a particular string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683392#M206985</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data WORK.IMPORT;
   infile datalines ;
   input person:$4. code_0:$4. code_1:$4. code_2:$4. code_3:$4. code_4:$4. code_5:$4.;
 datalines;
 Jane 345 I371 693 1125 G260 2461
 Jake G345 8170 565 8172 8701 2717
 Joan 890 8172 653 C980 3652 I370
 Mark 410 149 K628 3450 229 S280
 Mary 2797 D140 P635 1025 445 O980
 ;;;;

data want;
 set import;
 array icd code_0-code_5;
 indicator=0;
 do over icd;
  if icd in : ('345' '817' 'I37') then  indicator =1;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Sep 2020 01:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683392#M206985</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-09-12T01:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I search a range of columns for if any one of them starts with a particular string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683404#M206991</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;INDICATOR=prxmatch('/:(345|817|I37)/', ':'||catx(':',of CODE_0-CODE_5))&amp;gt;0;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 04:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683404#M206991</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-12T04:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: How can I search a range of columns for if any one of them starts with a particular string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683475#M207025</link>
      <description>&lt;P&gt;You don't want the ELSE in that type of search.&amp;nbsp; If you want values of one and zero instead of one and missing then set the value to zero before the do loop.&amp;nbsp; Also you can stop when you find one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array icd code_0-code_5;
indicator=0;
do i = 1 to dim(icd) until (indication);
  if icd[i]=:'345' or icd[i]=:'817' or icd[i]=:'I37' then indicator=1;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also use the special format of the IN function to search all of the array variables at once.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array icd code_0-code_5;
indicator=('345' in: icd) or ('817' in: icd) or ('I37' in: icd);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    person    code_0    code_1    code_2    code_3    code_4    code_5    indicator

 1      Jane      345       I371      693       1125      G260      2461         1
 2      Jake      G345      8170      565       8172      8701      2717         1
 3      Joan      890       8172      653       C980      3652      I370         1
 4      Mark      410       149       K628      3450      229       S280         1
 5      Mary      2797      D140      P635      1025      445       O980         0&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 00:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683475#M207025</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-13T00:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: How can I search a range of columns for if any one of them starts with a particular string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683992#M207218</link>
      <description>Thank you! This was perfect.</description>
      <pubDate>Tue, 15 Sep 2020 16:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-search-a-range-of-columns-for-if-any-one-of-them/m-p/683992#M207218</guid>
      <dc:creator>ESpiel</dc:creator>
      <dc:date>2020-09-15T16:15:55Z</dc:date>
    </item>
  </channel>
</rss>

