<?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 How to delete a group of observations based on below conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805293#M317204</link>
    <description>&lt;P&gt;How to delete a group of observations based on below conditions&lt;BR /&gt;/*if birthnum 2 and 3 or 2 and 6*/&lt;/P&gt;&lt;PRE&gt;/*How to delete a group of observations based on below conditions*/
/*if birthnum 2 and 3 or 2 and 6*/
 
data have;
  input id case_id birthnum $;
  datalines;
1 695 1
1 698 2
1 699 3
2 695 B
2 698 2
2 699 5
3 91  B
3 698 2
3 695 B
3 697 6
4 695 2
4 698 5
4 699 B
;

data want;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(where= (birthnum in ("2" "3" "6")))');
      h1.defineKey('id');
      h1.defineDone();
    end;
  set have;
  if h1.check()=0 then delete;
run;

proc print data=want;
run;


The output I want: However I am not getting this. It's zero Records am getting. 
2 695 B
2 698 2
2 699 5
4 695 2
4 698 5
4 699 B&lt;/PRE&gt;</description>
    <pubDate>Thu, 31 Mar 2022 14:21:17 GMT</pubDate>
    <dc:creator>Spintu</dc:creator>
    <dc:date>2022-03-31T14:21:17Z</dc:date>
    <item>
      <title>How to delete a group of observations based on below conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805293#M317204</link>
      <description>&lt;P&gt;How to delete a group of observations based on below conditions&lt;BR /&gt;/*if birthnum 2 and 3 or 2 and 6*/&lt;/P&gt;&lt;PRE&gt;/*How to delete a group of observations based on below conditions*/
/*if birthnum 2 and 3 or 2 and 6*/
 
data have;
  input id case_id birthnum $;
  datalines;
1 695 1
1 698 2
1 699 3
2 695 B
2 698 2
2 699 5
3 91  B
3 698 2
3 695 B
3 697 6
4 695 2
4 698 5
4 699 B
;

data want;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(where= (birthnum in ("2" "3" "6")))');
      h1.defineKey('id');
      h1.defineDone();
    end;
  set have;
  if h1.check()=0 then delete;
run;

proc print data=want;
run;


The output I want: However I am not getting this. It's zero Records am getting. 
2 695 B
2 698 2
2 699 5
4 695 2
4 698 5
4 699 B&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2022 14:21:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805293#M317204</guid>
      <dc:creator>Spintu</dc:creator>
      <dc:date>2022-03-31T14:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a group of observations based on below conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805299#M317207</link>
      <description>&lt;P&gt;have you tested your code? I reran it making check=h1.check(). check=0 for all of them. that's why you are not returning any observations.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 14:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805299#M317207</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-03-31T14:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a group of observations based on below conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805300#M317208</link>
      <description>&lt;P&gt;I think you are going to need to explain this more clearly&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/*if birthnum 2 and 3 or 2 and 6*/&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;How can a single observation (row) have a variable (birthnum) with values 2 and 3&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 14:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805300#M317208</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-03-31T14:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a group of observations based on below conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805305#M317212</link>
      <description>&lt;P&gt;if you look at the data ID 1 and 3 both have birthnum=2 and 3 or birthnum=2 and 6. I think the OP wishes to delete ones that ever have birthnum=2 and birthnum=3 or birthnum=2 and birthnum=6. that's the way I interpreted it from OP's post and desired output.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 14:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805305#M317212</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-03-31T14:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a group of observations based on below conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805306#M317213</link>
      <description>&lt;P&gt;Given the data are already sorted by ID, this is a single data step task.&amp;nbsp; Merge the subset with birthnum='2' with the subset having birtnum='3' or '6' with the entire set.&amp;nbsp; Keep those observations that don't have at least one member in both of the subsets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id case_id birthnum $;
  datalines;
1 695 1
1 698 2
1 699 3
2 695 B
2 698 2
2 699 5
3 91  B
3 698 2
3 695 B
3 697 6
4 695 2
4 698 5
4 699 B
;
data want;
  merge have (where=(birthnum='2') in=in2)
        have (where=(birthnum='3' or birthnum='6') in=in3or6)
        have ;
  by id;
  if not (in2=1 and in3or6=1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2022 14:32:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805306#M317213</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-31T14:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a group of observations based on below conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805314#M317215</link>
      <description>&lt;P&gt;This is an elegant solution with not too many lines of code!&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 14:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805314#M317215</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-03-31T14:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a group of observations based on below conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805316#M317217</link>
      <description>&lt;P&gt;If I am writing&amp;nbsp;&lt;SPAN&gt;check=h1.check() . It's creating a new variable check having missing&amp;nbsp;value. I am not getting my expected output.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 14:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805316#M317217</guid>
      <dc:creator>Spintu</dc:creator>
      <dc:date>2022-03-31T14:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a group of observations based on below conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805319#M317219</link>
      <description>&lt;P&gt;I suggested doing that so you could see the values are all 0 and that's why they got deleted. you should always open up datasets and see if you got desired results. it's a good way to check your work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 14:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805319#M317219</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-03-31T14:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a group of observations based on below conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805498#M317317</link>
      <description>&lt;PRE&gt; 
data have;
  input id case_id birthnum $;
  datalines;
1 695 1
1 698 2
1 699 3
2 695 B
2 698 2
2 699 5
3 91  B
3 698 2
3 695 B
3 697 6
4 695 2
4 698 5
4 699 B
;


proc sql;
create table want as
select * from have
 group by id
  having not (sum(birthnum='2') and sum(birthnum in ('3' '6')));
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Apr 2022 13:28:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805498#M317317</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-04-01T13:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete a group of observations based on below conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805545#M317333</link>
      <description>Thank you! Good to know that.</description>
      <pubDate>Fri, 01 Apr 2022 17:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-a-group-of-observations-based-on-below-conditions/m-p/805545#M317333</guid>
      <dc:creator>Spintu</dc:creator>
      <dc:date>2022-04-01T17:15:01Z</dc:date>
    </item>
  </channel>
</rss>

