<?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: Remove Observations based on a SAS table in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Observations-based-on-a-SAS-table/m-p/355650#M64200</link>
    <description>&lt;P&gt;Instead of a macro, consider using a function, like the hashin() function below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data status;
  input emp_no status :$8.;
datalines;
23333     expired
44444     active
66666     expired
run;
 
data base;
  input emp_no dob :date9. address :$&amp;amp;12.;
  format dob date9.;
datalines;
23333    26Oct1990   Street 1
44444    23jan1990   Street 2
66666    14feb1987   Street 3
run;
 
proc fcmp  outlib=work.temp.funcs;
  function hashin(emp_no);
    declare hash h (dataset:"mynames");
      rc=h.definekey("emp_no") ;
      rc=h.definedone();
  return (h.check()=0);
  endsub;
quit;

options cmplib=work.temp;

data mynames;
  set status;
  where status='active';
run;

data want;
  set base;
  where hashin(emp_no);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This also makes sense when you don't really need to save the WANT dataset, but just need to use it once&amp;nbsp;in a single&amp;nbsp;PROC, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=base;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where hashin(emp_no);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables a * b ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also it's easy to get the complement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=base;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where hashin(emp_no)=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables a * b;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My sources are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;A href="http://support.sas.com/kb/47/224.html" target="_self"&gt;Sample 47224: Load a SAS data set into a Hash Object using PROC FCMP&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;A href="http://support.sas.com/resources/papers/proceedings13/129-2013.pdf" target="_self"&gt;Hashing in PROC FCMP to Enhance Your Productivity&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 03 May 2017 15:40:00 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-05-03T15:40:00Z</dc:date>
    <item>
      <title>Remove Observations based on a SAS table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Observations-based-on-a-SAS-table/m-p/355532#M64193</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am writing a macro, which would remove records from my base dataset based on another table values(status), meaning&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;status table:&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; emp_no &amp;nbsp;status&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23333 &amp;nbsp; &amp;nbsp; expired&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 44444 &amp;nbsp; &amp;nbsp; &amp;nbsp;active&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; 66666 &amp;nbsp; &amp;nbsp; &amp;nbsp;expired&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Base table&lt;/P&gt;&lt;P&gt;id &amp;nbsp; emp_no &amp;nbsp; DOB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; address&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;23333 &amp;nbsp; &amp;nbsp; 26-Oct-1990 &amp;nbsp; Street 1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;44444 &amp;nbsp; &amp;nbsp;23-jan-1990 &amp;nbsp; &amp;nbsp; Street 2&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;66666 &amp;nbsp; &amp;nbsp; 14-feb-1987 &amp;nbsp; Street 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output table(required)&lt;/P&gt;&lt;P&gt;id&amp;nbsp;&lt;SPAN&gt;emp_no &amp;nbsp; DOB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; address&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2 &amp;nbsp; &amp;nbsp;44444 &amp;nbsp; &amp;nbsp;23-jan-1990 &amp;nbsp; &amp;nbsp; Street 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have done it using merge, is there any more efficient way to achieve the same. ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;create table status as (select empno,status from status where status = 'expired');run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data outputds;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;merge base(in=a) status(in=b)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;by emp_no;&lt;BR /&gt;if b then output expired;&lt;BR /&gt;else output outputds;&lt;BR /&gt;run;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2017 09:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Observations-based-on-a-SAS-table/m-p/355532#M64193</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2017-05-03T09:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Observations based on a SAS table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Observations-based-on-a-SAS-table/m-p/355538#M64194</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Post test data in the form of a datastep!&lt;/STRONG&gt; &amp;nbsp;This is the only way we can provide working code!&lt;/P&gt;
&lt;P&gt;Also, I do not see any macro there?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can simplfy your whole process down to one simple step:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  delete from BASE
  where EMP_NO in (select distinct EMP_NO from STATUS where STATUS="expired");
quit;&lt;/PRE&gt;
&lt;P&gt;Or you can create table with more or less the same syntax if you want a new table.&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2017 10:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Observations-based-on-a-SAS-table/m-p/355538#M64194</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-03T10:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Observations based on a SAS table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Observations-based-on-a-SAS-table/m-p/355544#M64195</link>
      <description>&lt;P&gt;You can do it in one data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data
  expired
  outputds
;
merge
  base (in=a)
  status (
    in=b
    where=(status = 'expired')
  )
;
by emp_no;
if b
then output expired;
else output outputds;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 May 2017 11:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Observations-based-on-a-SAS-table/m-p/355544#M64195</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-03T11:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Observations based on a SAS table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Remove-Observations-based-on-a-SAS-table/m-p/355650#M64200</link>
      <description>&lt;P&gt;Instead of a macro, consider using a function, like the hashin() function below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data status;
  input emp_no status :$8.;
datalines;
23333     expired
44444     active
66666     expired
run;
 
data base;
  input emp_no dob :date9. address :$&amp;amp;12.;
  format dob date9.;
datalines;
23333    26Oct1990   Street 1
44444    23jan1990   Street 2
66666    14feb1987   Street 3
run;
 
proc fcmp  outlib=work.temp.funcs;
  function hashin(emp_no);
    declare hash h (dataset:"mynames");
      rc=h.definekey("emp_no") ;
      rc=h.definedone();
  return (h.check()=0);
  endsub;
quit;

options cmplib=work.temp;

data mynames;
  set status;
  where status='active';
run;

data want;
  set base;
  where hashin(emp_no);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This also makes sense when you don't really need to save the WANT dataset, but just need to use it once&amp;nbsp;in a single&amp;nbsp;PROC, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=base;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where hashin(emp_no);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables a * b ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also it's easy to get the complement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=base;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where hashin(emp_no)=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables a * b;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My sources are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;A href="http://support.sas.com/kb/47/224.html" target="_self"&gt;Sample 47224: Load a SAS data set into a Hash Object using PROC FCMP&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;A href="http://support.sas.com/resources/papers/proceedings13/129-2013.pdf" target="_self"&gt;Hashing in PROC FCMP to Enhance Your Productivity&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2017 15:40:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Remove-Observations-based-on-a-SAS-table/m-p/355650#M64200</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-05-03T15:40:00Z</dc:date>
    </item>
  </channel>
</rss>

