<?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: Search for codes with arrray - excluding cases in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665024#M198767</link>
    <description>&lt;P&gt;Here is my approach - avoiding looping&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(drop=str);
input id$ dcode1 $ dcode2 $ dcode3 $;
array codes (*) $ dcode1-dcode3;
length str $32767;
str=cats(of codes[*]);
if (index(str,'J01XX05') gt 0) then
do;
	J01_flag = 0;
	C03_flag = 0;
end;
else
do;
	J01_flag = count(str,'J01')**0;
	C03_flag = count(str,'C03')**0;
end;
cards;
1 J01AA02 J01XX05 J01CA01
2  J01XX05 A10AB01 C03CA01
3  J01AA02 A10AB01 C03CA01
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 25 Jun 2020 14:19:56 GMT</pubDate>
    <dc:creator>AhmedAl_Attar</dc:creator>
    <dc:date>2020-06-25T14:19:56Z</dc:date>
    <item>
      <title>Search for codes with arrray - excluding cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665011#M198763</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the moment I am working with a very wide dataset, that contains more than 500 columns (not exactly following Maxim 19).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the dataset each row represents an individual and all their healthdata.&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;dcode1, dcode2...dcode500.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here is my dataset&amp;nbsp; (simplified)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input &lt;BR /&gt;id$ dcode1$ dcode2$ dcode3$;&lt;BR /&gt;cards;&lt;BR /&gt;1 J01AA02 J01XX05 J01CA01&lt;BR /&gt;2&amp;nbsp; J01XX05 A10AB01 C03CA01&lt;BR /&gt;3&amp;nbsp; J01AA02 A10AB01 A10AB01&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to count how many individuals that have a diagnosis that starts with 'J01', if they have a diagnosis that starts with 'J01' they will be assigned a 1 in the new variable J01_flag, else will get 0. But if they have the diagnosis 'J01XX05' I want to exclude them from the count in J01_flag.&lt;/P&gt;
&lt;P&gt;I want do a similar thing for every diagnosis that starts with 'C03'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;id dcode1 dcode2&amp;nbsp; dcode3&amp;nbsp; J01_flag C03_flag&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;1 J01AA02 J01XX05 J01CA01&amp;nbsp; 1&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;J01XX05 A10AB01 C03CA01 0 1&lt;/P&gt;
&lt;P&gt;3&amp;nbsp;J01AA02&amp;nbsp;A10AB01 C03CA01 1 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this possible to do with an array or any other function?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 13:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665011#M198763</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2020-06-25T13:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: Search for codes with arrray - excluding cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665018#M198765</link>
      <description>&lt;P&gt;please try below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array code(3) $ dcode1 dcode2 dcode3;
do i = 1 to 3;
if prxmatch('m/^J01/oi',code(i)) and code(i) ne 'J01XX05' then J01_flag=1;
if prxmatch('m/^C03/oi',code(i)) and code(i) ne 'J01XX05' then C03_flag=1;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 14:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665018#M198765</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-06-25T14:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Search for codes with arrray - excluding cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665024#M198767</link>
      <description>&lt;P&gt;Here is my approach - avoiding looping&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(drop=str);
input id$ dcode1 $ dcode2 $ dcode3 $;
array codes (*) $ dcode1-dcode3;
length str $32767;
str=cats(of codes[*]);
if (index(str,'J01XX05') gt 0) then
do;
	J01_flag = 0;
	C03_flag = 0;
end;
else
do;
	J01_flag = count(str,'J01')**0;
	C03_flag = count(str,'C03')**0;
end;
cards;
1 J01AA02 J01XX05 J01CA01
2  J01XX05 A10AB01 C03CA01
3  J01AA02 A10AB01 C03CA01
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 14:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665024#M198767</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2020-06-25T14:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: Search for codes with arrray - excluding cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665028#M198769</link>
      <description>&lt;P&gt;According to your description, ID 1 should have j01_flag as zero, as it has dcode2 as "&lt;SPAN&gt;J01XX05"; anyway, this is my code suggestion:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input 
id$ dcode1$ dcode2$ dcode3$;
cards;
1 J01AA02 J01XX05 J01CA01
2 J01XX05 A10AB01 C03CA01
3 J01AA02 A10AB01 A10AB01
;

proc transpose data=have out=long (drop=_name_ rename=(col1=dcode));
by id;
var dcode:;
run;

data want (drop=dcode dc);
merge
  long
  long (in=no rename=(dcode=dc) where=(dc="J01XX05"))
;
by id;
retain
  j01_flag
  c03_flag
;
if first.id
then do;
  j01_flag = 0;
  c03_flag = 0;
end;
if index(dcode,'J01') = 1 then j01_flag = 1;
if index(dcode,'C03') = 1 then c03_flag = 1;
if last.id;
if no then j01_flag = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;You can merge the result back to dataset have.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 14:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665028#M198769</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-25T14:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Search for codes with arrray - excluding cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665029#M198770</link>
      <description>&lt;P&gt;Your code will produce false positives if the strings J01 or C03 appear &lt;EM&gt;within&lt;/EM&gt; a dcode.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 14:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665029#M198770</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-25T14:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Search for codes with arrray - excluding cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665209#M198863</link>
      <description>&lt;P&gt;If variety is the spice of life ...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array code(500) $ dcode1-dcode500;
J01_flag=0;
C03_flag=0;
do i = 1 to 500 until (J01_flag=1 and C03_flag=1);
   if code(i)=: 'J01' and code(i) ne 'J01XX05' then J01_flag=1;
   if code(i)=: 'C03' and code(i) ne 'C03XX05' then C03_flag=1;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There are small parts of the logic that you may need to tweak, since the question left them to the imagination.&amp;nbsp; If one observation contains both a diagnosis of J01XX05 and another diagnosis of J01CA01, it seems that that should count as J01_flag=1.&amp;nbsp; But perhaps not ... easy enough to change if needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, the C03 "do not use" value seems like it should be C03XX05 but perhaps that is not correct as well.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 00:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-codes-with-arrray-excluding-cases/m-p/665209#M198863</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-06-26T00:55:55Z</dc:date>
    </item>
  </channel>
</rss>

