<?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: Applying diagnosis code to identify specific patients in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/687155#M208590</link>
    <description>Hello,&lt;BR /&gt;Thank a lot for your help! It worked!</description>
    <pubDate>Mon, 28 Sep 2020 09:49:16 GMT</pubDate>
    <dc:creator>ftahsin</dc:creator>
    <dc:date>2020-09-28T09:49:16Z</dc:date>
    <item>
      <title>Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/682543#M206602</link>
      <description>&lt;P&gt;Hello SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a Medicaid dataset.&amp;nbsp;I have the patient ID's and several diagnosis codes for those patients. I have the following data-&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data have;
input     ID    Diagnosis1 $  Diagnosis2 $  Diagnosis3 $  Diagnosis4 $;
datalines;
6816494         6910             6869          147           V061
6816515         463              2893          741           V061
6816515         462              78499         V061          V053
6819880         741              78791         77081         7730
;
run;&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;I want data that will specify the patients who were diagnosed with some specific codes (i.e., 740, 741..., etc.). So, I am looking for the following data-&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input     ID    Diagnosis1 $  Diagnosis2  $  Diagnosis3 $  Diagnosis4 $  Patient;
datalines;
6816494         6910             6869          147           V061            0
6816515         463              2893          741           V061            1
6816515         462              78499         V061          V053            0
6819880         741              78791         77081         7730            1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Note: the example I gave has 4 diagnoses, but my original dataset has 8 diagnoses.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you so much. Your assistance with the code is appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 08:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/682543#M206602</guid>
      <dc:creator>ftahsin</dc:creator>
      <dc:date>2020-09-09T08:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/682802#M206719</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;FLAG = prxmatch('/&lt;SPAN&gt;740|741&lt;/SPAN&gt;/',catx('|',of DIAGNOSIS1-DIAGNOSIS8));&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 23:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/682802#M206719</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-09T23:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/682812#M206726</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332600"&gt;@ftahsin&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to show a useful technique with the IN operator which I will use to address the problem you presented.&amp;nbsp;&amp;nbsp;The solution presented by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;is quite succinct, and I don't intend in any way to argue that my solution is somehow "better;" it's just another approach and a useful technique.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET	Diagnoses	=	4;
%LET	Searches	=	2;

DATA	Want;
	SET	Have;
	ARRAY	Diagnoses	[&amp;amp;Diagnoses]	$5	Diagnosis1 - Diagnosis&amp;amp;Diagnoses;
	ARRAY	Search_For	[&amp;amp;Searches]		$5	_temporary_	('740' '741');
&lt;BR /&gt;	Patient			=	0;
	DO	i			=	1		TO	&amp;amp;Searches;
		IF		Search_For[i]	IN	Diagnoses	THEN
			Patient	=	1;
	END;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The IN operator here is used to check the entire Diagnoses array for a particular value (here, either 740 or 741).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 05:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/682812#M206726</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-19T05:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/684843#M207614</link>
      <description>Hello JIM,&lt;BR /&gt;Thanks a lot for your response. I tried to run your code by modifying it a bit according to my variables. I actually have 9 diagnoses named PDIAG and SDIAG1 - SDIAG8 (PDIAG = primary diagnosis, SDIAG = secondary diagnosis). And the number of my searches will be 19 (740 - 758). So, I tried the following code:&lt;BR /&gt;&lt;BR /&gt;%LET PDIAG = 1;&lt;BR /&gt;%LET SDIAG = 8;&lt;BR /&gt;%LET Searches = 19;&lt;BR /&gt;&lt;BR /&gt;DATA want;&lt;BR /&gt;SET have;&lt;BR /&gt;ARRAY PDIAG [&amp;amp;PDIAG] $10 SDIAG1 - SDIAG8 $10;&lt;BR /&gt;ARRAY Search_For [&amp;amp;Searches] $10 _temporary_ ('740' '741' '742' '743' '744' '745' '746' '747' '748' '749' '750' '751' '752' '753' '754' '755' '756' '740' '757' '758');&lt;BR /&gt;&lt;BR /&gt;DO i = 1 TO &amp;amp;Searches;&lt;BR /&gt;IF Search_For[i] IN PDIAG and SDIAG1-SDIAG8 THEN&lt;BR /&gt;Patient = 1;&lt;BR /&gt;ELSE&lt;BR /&gt;Patient = 0;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;Unfortunately, it didn't work. Can you please tell me what did I do wrong? It will be a great help!</description>
      <pubDate>Fri, 18 Sep 2020 01:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/684843#M207614</guid>
      <dc:creator>ftahsin</dc:creator>
      <dc:date>2020-09-18T01:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/684857#M207619</link>
      <description>&lt;P&gt;My statement becomes&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;FLAG = prxmatch('/74\d|75[0-8]/',catx('|',of SDIAG1-SDIAG8, PDIAG ));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;FLAG = prxmatch('/74[0-9]|75[0-8]/',catx('|',of SDIAG1-SDIAG8, PDIAG ));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;with your new requirements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also see &lt;A href="https://communities.sas.com/t5/SAS-Programming/Comparing-vars-against-three-values-and-then-creating-new-var-if/m-p/684451#M207417" target="_self"&gt;an alternative syntax&lt;/A&gt; for an IN match, by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 02:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/684857#M207619</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-18T02:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/684900#M207643</link>
      <description>Hello ChrisNZ,&lt;BR /&gt;Thanks a lot for your reply. I tried your code and it runs. But I got values like this-&lt;BR /&gt;&lt;BR /&gt;Flag&lt;BR /&gt;0&lt;BR /&gt;0&lt;BR /&gt;18&lt;BR /&gt;18&lt;BR /&gt;7&lt;BR /&gt;40&lt;BR /&gt;0&lt;BR /&gt;0&lt;BR /&gt;1&lt;BR /&gt;Where it should be only 0 or 1 based on the presence of any of the diagnosis codes. Can you please tell me how I can fix this?&lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;Farah</description>
      <pubDate>Fri, 18 Sep 2020 07:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/684900#M207643</guid>
      <dc:creator>ftahsin</dc:creator>
      <dc:date>2020-09-18T07:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/684906#M207647</link>
      <description>&lt;P&gt;Just add a test:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;FLAG = prxmatch('/74\d|75[0-8]/',catx('|',of SDIAG1-SDIAG8, PDIAG )) &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&amp;gt; 0&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 07:52:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/684906#M207647</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-18T07:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/685100#M207731</link>
      <description>&lt;P&gt;You might give this a try:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; 
set have;
sdiag0=pdiag; /*change your PDIAG variable to be consistent with the SDIAG variables*/
array DiagVar sdiag0-sdiag8;
flag = 0;
do over DiagVar;
if DiagVar in: ('740' '741' '742' '743' '744' '745' '746' '747' '748' '749' '750' '751' '752' '753' '754' '755' '756' '740' '757' '758') then flag = 1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2020 20:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/685100#M207731</guid>
      <dc:creator>eabc0351</dc:creator>
      <dc:date>2020-09-18T20:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/685146#M207753</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332600"&gt;@ftahsin&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your modified code looks pretty good, but there are a couple of small things that are going to hold you back.&amp;nbsp; You defined the array as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET PDIAG = 1;
ARRAY PDIAG [&amp;amp;PDIAG] $10 SDIAG1 - SDIAG8 $10;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;OL&gt;
&lt;LI&gt;You can't use the same name for your array as for the variable itself.&amp;nbsp; In other words, you can't have both a PDIAG array and a PDIAG variable.&amp;nbsp; Instead of PDIAG for the diagnoses array name, let's use the name Diagnoses.&lt;/LI&gt;
&lt;LI&gt;If you define your array as &lt;SPAN style="font-family: inherit;"&gt;Diagnoses[&amp;amp;PDIAG&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;], you're only going to get 1 occurrence in the array (the macro variable PDIAG resolves to 1).&amp;nbsp; Rather than 1, you have 9 diagnoses (one primary and eight secondary), so you need to define your array as &lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;Diagnoses[&lt;/SPAN&gt;&lt;FONT size="4" style="font-family: inherit;"&gt;&lt;STRONG&gt;9&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN style="font-family: inherit;"&gt;].&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN style="font-family: inherit;"&gt;If you count, you actually have twenty, not nineteen occurrences in your Search_For array.&amp;nbsp; The value '740' is repeated twice.&amp;nbsp; You need to remove the second '740' or you'll lose the last occurrence in the array.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN style="font-family: inherit;"&gt;&lt;SPAN style="font-family: inherit;"&gt;In your IF statement, you coded:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF Search_For[i] IN PDIAG and SDIAG1-SDIAG8 THEN&lt;/CODE&gt;&lt;/PRE&gt;
&lt;SPAN style="font-family: inherit;"&gt;You don't want to code "PDIAG and SDIAG1 - SDIAG8".&amp;nbsp; This is what we created the array for.&amp;nbsp; When we created the array Diagnoses, Diagnoses was assigned as "ARRAY Diagnoses [&amp;amp;Diagnoses] $5 &lt;STRONG&gt;PDiag SDiag1 - SDiag8&lt;/STRONG&gt;;"&amp;nbsp; So, when you refer to the array name, you're &lt;EM&gt;already&lt;/EM&gt; referring to "PDiag SDiag1 - SDiag8", so you don't need to code it all over again.&amp;nbsp; Just code the &lt;EM&gt;name&lt;/EM&gt; of the array.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN style="font-family: inherit;"&gt;When you set your Patient value to 0, the best way to do that is &lt;EM&gt;before&lt;/EM&gt; you go through the Search_For loop.&amp;nbsp; If you set the patient value to 0 as part of an ELSE, you might overlay a value of 1 determined in an earlier iteration. I originally coded it that way and caught the bug later and corrected it.&amp;nbsp; You grabbed my code before I corrected the bug, so this one's not your fault.&amp;nbsp; I have now corrected the bug, and you should too.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Try adjusting your program for the five things I've listed above and re-running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you get stuck, I've&amp;nbsp;coded everything up below so you have a working solution that you can compare against.&amp;nbsp; In the sample data I created, the odd numbered rows should derive Patient = 0, and the even numbered rows should derive Patient = 1.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added one new thing to the code:&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;i = &amp;amp;Searches; &amp;nbsp;&lt;/CODE&gt;Any time we find a condition that causes Patient to be set to 1, there's really no need to check any further.&amp;nbsp; We already know that Patient = 1.&amp;nbsp; So, I set the index to the maximum number, which causes the DO loop to stop further searches on the current record.&amp;nbsp; With only two search elements per record in the original version, there wasn't a lot of savings to be gained by not performing some of the searches, but now with 19 searches per second, you can save some time by avoiding unnecessary searches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Have;
	INFILE	DATALINES4;
	INPUT
		ID
		PDiag  $
		SDiag1 $
		SDiag2 $
		SDiag3 $
		SDiag4 $
		SDiag5 $
		SDiag6 $
		SDiag7 $
		SDiag8 $
		;
DATALINES4;
6816494 6910 6869  147   V061 6910 6869  759   V061 147
6816515 463  2893  741   V061 463  2893  1741  V061 2741
6816515 462  78499 V061  V053 462  78499 717   V053 V061
6819880 791  78791 77081 7730 708  78791 77081 7730 744
6819881 721  78791 77081 7730 799  78791 77081 7730 77081
6819882 711  78791 77081 7730 758  78791 77081 7730 77081
6819883 701  78791 77081 7730 058  78791 77081 7730 77081
6819884 703  78791 77081 7730 7581 78791 77081 755  77081
6819885 714  78791 77081 7730 1758 78791 77081 7730 77081
6819886 241  78791 77081 7730 888  78791 77081 7730 740
;;;;
RUN;

%LET	Diagnoses	=	9;
%LET	Searches	=	19;

DATA	Want;
	DROP	i;
	SET	Have;
	ARRAY	Diagnoses	[&amp;amp;Diagnoses]	$5	PDiag SDiag1 - SDiag8;
	ARRAY	Search_For	[&amp;amp;Searches]		$5	_temporary_	('740' '741' '742' '743' '744' 
														 '745' '746' '747' '748' '749' 
														 '750' '751' '752' '753' '754' 
														 '755' '756' '757' '758');

	Patient				=	0;

	DO	i			=	1	TO	&amp;amp;Searches;
		IF	Search_For[i]	IN	Diagnoses	THEN
			DO;
				Patient	=	1;
				i		=	&amp;amp;Searches;
			END;
	END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 05:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/685146#M207753</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-19T05:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/687154#M208589</link>
      <description>Hello Jim,&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for explaining these to me. I am a beginner in SAS, so the points you made are very informative to me. I will keep them in mind whenever I work with these types of codes.&lt;BR /&gt;&lt;BR /&gt;I tried your code and it ran. For some reason, I was getting 0 for all my patients, although manually I can see a considerable number of people have those specific diagnoses codes. But I fixed it, so no issues! Thanks again for your help.&lt;BR /&gt;&lt;BR /&gt;-Farah</description>
      <pubDate>Mon, 28 Sep 2020 09:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/687154#M208589</guid>
      <dc:creator>ftahsin</dc:creator>
      <dc:date>2020-09-28T09:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Applying diagnosis code to identify specific patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/687155#M208590</link>
      <description>Hello,&lt;BR /&gt;Thank a lot for your help! It worked!</description>
      <pubDate>Mon, 28 Sep 2020 09:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-diagnosis-code-to-identify-specific-patients/m-p/687155#M208590</guid>
      <dc:creator>ftahsin</dc:creator>
      <dc:date>2020-09-28T09:49:16Z</dc:date>
    </item>
  </channel>
</rss>

