<?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 do I extract a range of ICD codes from several variables to create a 2-level indicator? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-range-of-ICD-codes-from-several-variables-to/m-p/948634#M371142</link>
    <description>&lt;P&gt;To detect ANY set the result FALSE before the loop.&amp;nbsp; The loop over the array storing the result of the test, stopping when it is TRUE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dx_intest=0;
do i = 1 to dim(old) while (not dx_intest);
  dx_intest= ( old[i] in: ('A' 'B') );
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or even easier just stop once it is TRUE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i = 1 to dim(old) until(dx_intest);
  dx_intest= ( old[i] in: ('A' 'B') );
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Oct 2024 17:55:23 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-10-22T17:55:23Z</dc:date>
    <item>
      <title>How do I extract a range of ICD codes from several variables to create a 2-level indicator?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-range-of-ICD-codes-from-several-variables-to/m-p/948629#M371137</link>
      <description>&lt;P&gt;I'm working with ICD-10/ICD-10M codes, with about 22 different variables to pull the codes from.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create 2-level indicator variable for each of the main ICD groups, so that if a record has any of the diagnosis codes, they'll fall into the respective bucket. For example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 'A00' - 'B99' = 'Intestinal Infectious Disease'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what I'm doing is only returning DX_intest = 0.&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY old [22] h_Diag1 - h_Diag18   h_Admit_Diag_Cd  h_Patient_Reason_Visit1 - h_Patient_Reason_Visit3 ;

Do i = 1 to 22;		
	If substr(OLD(i),1,3) in ("A:") OR  substr(OLD(i),1,3) in ("B:") then DX_intest=1;
	Else DX_all=0;
end;	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;Ultimately, I want to return "1" for DX_intest if any of the variables listed in the array contain ICD codes of A00 through B99; otherwise, return DX_intest = 0;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2024 17:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-range-of-ICD-codes-from-several-variables-to/m-p/948629#M371137</guid>
      <dc:creator>SAS93</dc:creator>
      <dc:date>2024-10-22T17:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract a range of ICD codes from several variables to create a 2-level indicator?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-range-of-ICD-codes-from-several-variables-to/m-p/948633#M371141</link>
      <description>&lt;P&gt;If you are trying to find "begins with" don't use&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt; in ("A:")&lt;/LI-CODE&gt;
&lt;P&gt;that tries to match 3 selected characters with exactly 2 and includes the : . So nothing matches.&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data example;
   input code $;
   if code in: ('A' 'B') then put 'Found ' code=;
datalines;
A00456
B12456
C00000
;&lt;/PRE&gt;
&lt;P&gt;However you current program would return only the value of the LAST variable compared: h_Patient_Reason_Visit3&lt;/P&gt;
&lt;P&gt;So you might want:&lt;/P&gt;
&lt;PRE&gt;ARRAY old [22] h_Diag1 - h_Diag18   h_Admit_Diag_Cd  h_Patient_Reason_Visit1 - h_Patient_Reason_Visit3 ;

dx_all=0;
Do i = 1 to 22;		
   dx_intest= substr(OLD(i),1,3) in: ("A" "B");&lt;BR /&gt;   if DX_intest=1 then do;&lt;BR /&gt;      dx_all = .;
      leave;
   end;
	
end;	&lt;/PRE&gt;
&lt;P&gt;You don't say what dx_all is supposed to represent so I am guessing on that point that you don't want dx_all to be 0 when you find one of the codes.&lt;/P&gt;
&lt;P&gt;The LEAVE instruction exits a do loop (caution with nested loops as to which it leaves). So when you find the first A or B this sets the value of DX_intest to 1 then ends the loop and stops searching. A side effect of this code is that the variable i will have the index of the variable in the array where the value was found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will return 1 for True comparisons and 0 for false. So if none of the variables have the condition true the result at completion of the array tested will be 0.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2024 17:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-range-of-ICD-codes-from-several-variables-to/m-p/948633#M371141</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-10-22T17:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract a range of ICD codes from several variables to create a 2-level indicator?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-range-of-ICD-codes-from-several-variables-to/m-p/948634#M371142</link>
      <description>&lt;P&gt;To detect ANY set the result FALSE before the loop.&amp;nbsp; The loop over the array storing the result of the test, stopping when it is TRUE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dx_intest=0;
do i = 1 to dim(old) while (not dx_intest);
  dx_intest= ( old[i] in: ('A' 'B') );
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or even easier just stop once it is TRUE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i = 1 to dim(old) until(dx_intest);
  dx_intest= ( old[i] in: ('A' 'B') );
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2024 17:55:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-range-of-ICD-codes-from-several-variables-to/m-p/948634#M371142</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-22T17:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract a range of ICD codes from several variables to create a 2-level indicator?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-range-of-ICD-codes-from-several-variables-to/m-p/948637#M371144</link>
      <description>&lt;P&gt;Move the zero assignment out of the loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DX_intest = 0;
do i = 1 to 22;		
  if substr(OLD{i},1,1) eq "A" or substr(OLD{i},1,1) eq "B" then DX_intest = 1;
end;	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that you can not use wildcards to build a list for the IN operator. All values in the IN list must be explicitly coded. If necessary, you can store all wanted ICD codes in a dataset and use it to build code dynamically.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2024 18:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-extract-a-range-of-ICD-codes-from-several-variables-to/m-p/948637#M371144</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-10-22T18:02:23Z</dc:date>
    </item>
  </channel>
</rss>

