<?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: filtering out records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631335#M187049</link>
    <description>There are many rows per patient&lt;BR /&gt;what im trying to get is the patients who received services 4, or 13, or 20 along with 5 or 6 or 7 or 8&lt;BR /&gt;but if they received only 4, or 13, or 20 then dont keep them&lt;BR /&gt;</description>
    <pubDate>Wed, 11 Mar 2020 18:13:30 GMT</pubDate>
    <dc:creator>Ranjeeta</dc:creator>
    <dc:date>2020-03-11T18:13:30Z</dc:date>
    <item>
      <title>filtering out records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631319#M187040</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data discard keep;
set input;
by id;
if service in (4,13,20) then output discard;
if service in (4,5,6,7,8,13,20) then output keep;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Can someone advise if the code above is correct to filter out the following records&lt;/P&gt;&lt;P&gt;If a patient has service equal to only 4 or 13, or 20 the exclude those patients&lt;/P&gt;&lt;P&gt;but if a patient has service equal to 5 or 6 or 7 or 8 along with&amp;nbsp;4 or 13, or 20 then keep them&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 17:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631319#M187040</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2020-03-11T17:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: filtering out records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631325#M187043</link>
      <description>&lt;P&gt;Ranjeeta,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would re-code as follows otherwise you will have cases with the same patient occurring in &lt;EM&gt;both&lt;/EM&gt; output datasets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data discard keep;
set input;
by id;
if  service in (4,13,20) then 
    output discard;
else
    output keep;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 18:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631325#M187043</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-03-11T18:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: filtering out records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631327#M187045</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend that you use another name than "keep" for your output dataset as it may be confusing (SAS word).&lt;/P&gt;
&lt;P&gt;There is an inconsistency in your code between both IF statements:&lt;/P&gt;
&lt;P&gt;-&amp;gt; a patient who will have service=4 or 13 or 20 will be kept in both tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your input dataset, are there many rows by patient?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data discard keep;
set input;
by id;
if service in (4,13,20) then output discard;
if service in (4,5,6,7,8,13,20) then output keep;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Mar 2020 18:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631327#M187045</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-11T18:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: filtering out records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631335#M187049</link>
      <description>There are many rows per patient&lt;BR /&gt;what im trying to get is the patients who received services 4, or 13, or 20 along with 5 or 6 or 7 or 8&lt;BR /&gt;but if they received only 4, or 13, or 20 then dont keep them&lt;BR /&gt;</description>
      <pubDate>Wed, 11 Mar 2020 18:13:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631335#M187049</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2020-03-11T18:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: filtering out records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631342#M187052</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please test if the following code meet your expectations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Retrieve the list of id for each table*/
proc transpose data=input out=input_tr (drop=_:) prefix=service;
	var service;
	by id;
run;

data id_tobediscarded id_tobekept;
	set input_tr;
	by id;
	length service_all $ 20;
	service_all = catx(",",of service:);
	if prxmatch('/(4|13|20)/',service_all) and prxmatch('/(5|6|7|8)/',service_all) then output id_tobekept;
	else if prxmatch('/(4|13|20)/',service_all) then output id_tobediscarded;
	drop service:;
run;

proc sql;
/*First table: keep*/
	create table keep as
	select a.*
	from input as a inner join id_tobekept as b
	on a.id = b.id;
/*Second table: discard*/
	create table discard as
	select a.*
	from input as a inner join id_tobediscarded as b
	on a.id = b.id;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Mar 2020 18:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631342#M187052</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-11T18:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: filtering out records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631352#M187062</link>
      <description>&lt;P&gt;Are there other codes that may have to be ignored besides those values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;There are many rows per patient&lt;BR /&gt;what im trying to get is the patients who received services 4, or 13, or 20 along with 5 or 6 or 7 or 8&lt;BR /&gt;but if they received only 4, or 13, or 20 then dont keep them&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 19:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631352#M187062</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-11T19:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: filtering out records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631356#M187065</link>
      <description>&lt;P&gt;Thankyou was just trying the code but the 2nd step&amp;nbsp;is not returning any obs&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; id_tobediscarded id_tobekept&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; input_tr&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;id&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token function"&gt;length&lt;/SPAN&gt; service_all &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;20&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	service_all &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;catx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;","&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;of service:&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;prxmatch&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'/(4|13|20)/'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;service_all&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; and &lt;SPAN class="token function"&gt;prxmatch&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'/(5|6|7|8)/'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;service_all&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; output id_tobekept&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;prxmatch&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'/(4|13|20)/'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;service_all&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; output id_tobediscarded&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;drop&lt;/SPAN&gt; service:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 19:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631356#M187065</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2020-03-11T19:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: filtering out records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631358#M187066</link>
      <description>No there are no other service codes that need to be ignored</description>
      <pubDate>Wed, 11 Mar 2020 19:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-out-records/m-p/631358#M187066</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2020-03-11T19:37:44Z</dc:date>
    </item>
  </channel>
</rss>

