<?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: Selecting multiple codes and excluding certain codes - array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-codes-and-excluding-certain-codes-array/m-p/667166#M199727</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321775"&gt;@Chris_LK_87&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this code meet your needs?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array code(*) $ atc1-atc500;
	Hypertension=0;
	J01_flag=0;

	do i=1 to dim(code);
		if prxmatch('/(C02|C03|C07|C08|C09).*/',code(i)) and code(i) not in ('C02AC02','C07AA07') then Hypertension=1;
		if prxmatch('/(J01).*/',code(i)) and code(i) ne 'J01XX05' then J01_flag=1;
	end;
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jul 2020 12:52:52 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-07-06T12:52:52Z</dc:date>
    <item>
      <title>Selecting multiple codes and excluding certain codes - array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-codes-and-excluding-certain-codes-array/m-p/667148#M199725</link>
      <description>&lt;P&gt;I have a quite large dataset with many columns (500+).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each row contains information about one individual and their diagnosiscode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to select multiple diagnosiscodes and at the same time exclude certain&amp;nbsp;diagnosiscodes &amp;nbsp;by using an array and put them in a group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for example I would like to create a variable for hypertension. So every individual that has one of the following diagnosiscode; 'C02', 'C03', 'C07','C08', 'C09'&amp;nbsp; will get a 1 assigned for the variable hypertension else will get 0. But if they have diagnosiscode 'C02AC02' or 'C07AA07' they&lt;/P&gt;
&lt;P&gt;will not get a 1 for hypertension (but if any of their other diagnosiscode is 'C02', 'C03', 'C07','C08', 'C09' they will get a 1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been using an&amp;nbsp;array, see code below, but I haven’t been able to figure out how to select multiple codes while excluding other codes at the same time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;input&lt;/P&gt;
&lt;P&gt;id$ atc1$ atc2$ atc3$;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; J01&amp;nbsp; J01XX05&amp;nbsp; C07&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; J01XX05&amp;nbsp; A10A&amp;nbsp; C03C&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; C02&amp;nbsp; A10A&amp;nbsp; A10B&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; C07AA07&amp;nbsp; C02&amp;nbsp; A10B&lt;/P&gt;
&lt;P&gt;5&amp;nbsp; C07AA07&amp;nbsp; C02AC02&amp;nbsp; J01&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&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;This is the code I have been using but I don’t get it to work. I have got it to work if I want to select one code and exclude another code (as the one use for J01_flag).&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array code(500) $ atc1-atc500;&lt;/P&gt;
&lt;P&gt;Hypertension=0;&lt;/P&gt;
&lt;P&gt;J01_flag=0;&lt;/P&gt;
&lt;P&gt;do i = 1 to 500 until (Hypertension=1 and J01_flag=1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if code(i)=: 'C02' or&amp;nbsp; 'C03' or&amp;nbsp; 'C07' or 'C08' or 'C09'&amp;nbsp; and code(i) ne 'C02AC02' or 'C07AA07' then Hypertension=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if code(i)=: ‘J01’ and code(i) ne ' J01XX05' then J01_flag=1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop i;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;id$ atc1$ atc2$ atc3$ Hypertoni$ J01_flag$;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; J01&amp;nbsp; J01XX05&amp;nbsp; C07 1 1&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; J01XX05&amp;nbsp; A10A&amp;nbsp; C03C&amp;nbsp; 1 0&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; C02 A10A&amp;nbsp; A10B 1 0&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; C07AA07&amp;nbsp; C02 A10B 1 0&lt;/P&gt;
&lt;P&gt;5&amp;nbsp; C07AA07&amp;nbsp; C02AC02 J01 0 1&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&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>Mon, 06 Jul 2020 12:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-codes-and-excluding-certain-codes-array/m-p/667148#M199725</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2020-07-06T12:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple codes and excluding certain codes - array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-codes-and-excluding-certain-codes-array/m-p/667166#M199727</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321775"&gt;@Chris_LK_87&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this code meet your needs?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array code(*) $ atc1-atc500;
	Hypertension=0;
	J01_flag=0;

	do i=1 to dim(code);
		if prxmatch('/(C02|C03|C07|C08|C09).*/',code(i)) and code(i) not in ('C02AC02','C07AA07') then Hypertension=1;
		if prxmatch('/(J01).*/',code(i)) and code(i) ne 'J01XX05' then J01_flag=1;
	end;
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 12:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-codes-and-excluding-certain-codes-array/m-p/667166#M199727</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-07-06T12:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple codes and excluding certain codes - array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-codes-and-excluding-certain-codes-array/m-p/667170#M199728</link>
      <description>&lt;P&gt;This doesn't make any sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if code(i)=: 'C02' or  'C03' or  'C07' or 'C08' or 'C09' &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are combining character strings with the boolean operator OR.&lt;/P&gt;
&lt;P&gt;Are you looking for the IN operator instead?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if code(i) in: ('C02'  'C03'  'C07'  'C08'  'C09')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 13:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-codes-and-excluding-certain-codes-array/m-p/667170#M199728</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-06T13:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple codes and excluding certain codes - array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-codes-and-excluding-certain-codes-array/m-p/667389#M199844</link>
      <description>&lt;P&gt;Thanks for replying.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code selects other diagnosiscodes that I am not looking for, for example everything that contains 'C02' like 'R03AC02'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way around this?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 09:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-codes-and-excluding-certain-codes-array/m-p/667389#M199844</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2020-07-07T09:27:33Z</dc:date>
    </item>
  </channel>
</rss>

