<?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: delete sets of observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10277#M731</link>
    <description>Got it,  Thanks!</description>
    <pubDate>Tue, 24 Mar 2009 19:52:35 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-03-24T19:52:35Z</dc:date>
    <item>
      <title>delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10267#M721</link>
      <description>I would like to delete certain small subsets of my data.&lt;BR /&gt;
&lt;BR /&gt;
For example say I have a set like this:&lt;BR /&gt;
A     B      C     D&lt;BR /&gt;
1      0      2      3&lt;BR /&gt;
1      10    2      2 &lt;BR /&gt;
1      4      3      2&lt;BR /&gt;
2      2      3       3&lt;BR /&gt;
2      6      7       3&lt;BR /&gt;
2      3      3       2&lt;BR /&gt;
2      7      3       2&lt;BR /&gt;
3      1      0       3&lt;BR /&gt;
3      5      3       2&lt;BR /&gt;
3      7      1       3&lt;BR /&gt;
&lt;BR /&gt;
I would like to delete the sets of observations with matching A values for which the there is an observation with the B value equal to zero.  So it would look like this:&lt;BR /&gt;
&lt;BR /&gt;
A     B      C     D&lt;BR /&gt;
2      2      3       3&lt;BR /&gt;
2      6      7       3&lt;BR /&gt;
2      3      3       2&lt;BR /&gt;
2      7      3       2&lt;BR /&gt;
3      1      0       3&lt;BR /&gt;
3      5      3       2&lt;BR /&gt;
3      7      1       3&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
something like &lt;BR /&gt;
&lt;BR /&gt;
data data_set;&lt;BR /&gt;
     set data_set;&lt;BR /&gt;
     if B='0' then ??????;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the help.</description>
      <pubDate>Tue, 24 Mar 2009 16:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10267#M721</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T16:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10268#M722</link>
      <description>Something like:&lt;BR /&gt;
&lt;BR /&gt;
*flag the observations with a B=0;&lt;BR /&gt;
data flags;&lt;BR /&gt;
set input;&lt;BR /&gt;
if b=0 then flag=1;&lt;BR /&gt;
else flag=0;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*keep all the observations without a flagged observation in their group;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table no_zeros as&lt;BR /&gt;
select *, max(flag) as zeros&lt;BR /&gt;
from flags&lt;BR /&gt;
group by A&lt;BR /&gt;
having calculated zeros=0;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
I think that will do it. Correct me if I'm wrong.</description>
      <pubDate>Tue, 24 Mar 2009 16:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10268#M722</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T16:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10269#M723</link>
      <description>proc sql;&lt;BR /&gt;
delete from data_set where a in (select distinct a from data_set where b = 0);&lt;BR /&gt;
quit;</description>
      <pubDate>Tue, 24 Mar 2009 16:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10269#M723</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-24T16:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10270#M724</link>
      <description>I tried this and received the error below.  I will try the first example now.  Thanks.&lt;BR /&gt;
&lt;BR /&gt;
15  proc sql;&lt;BR /&gt;
116  delete from aptest where date and racenum in (select distinct date and racenum from aptest where&lt;BR /&gt;
116! lifestarts = 0);&lt;BR /&gt;
WARNING: This DELETE/INSERT statement recursively references the target table. A consequence of this&lt;BR /&gt;
         is a possible data integrity problem.&lt;BR /&gt;
NOTE: 3071 rows were deleted from WORK.APTEST.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
but there still remain observations for which   lifestarts=0.</description>
      <pubDate>Tue, 24 Mar 2009 17:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10270#M724</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T17:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10271#M725</link>
      <description>also received this error for the first attempt:&lt;BR /&gt;
&lt;BR /&gt;
140  proc sql;&lt;BR /&gt;
141  create table no_zeros as&lt;BR /&gt;
142  select *, max(flag) as zeros&lt;BR /&gt;
143  from flags&lt;BR /&gt;
144  group by date and racenum&lt;BR /&gt;
145  having calculated zeros=0;&lt;BR /&gt;
NOTE: The query requires remerging summary statistics back with the original data.&lt;BR /&gt;
NOTE: Table WORK.NO_ZEROS created, with 0 rows and 1479 columns.</description>
      <pubDate>Tue, 24 Mar 2009 17:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10271#M725</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T17:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10272#M726</link>
      <description>140 proc sql;&lt;BR /&gt;
141 create table no_zeros as&lt;BR /&gt;
142 select *, max(flag) as zeros&lt;BR /&gt;
143 from flags&lt;BR /&gt;
144 group by date and racenum&lt;BR /&gt;
145 having calculated zeros=0;&lt;BR /&gt;
&lt;BR /&gt;
Firstly it's not an ERROR, it's a note. However you need to do &lt;BR /&gt;
&lt;BR /&gt;
group by date, racenum&lt;BR /&gt;
&lt;BR /&gt;
not &lt;BR /&gt;
&lt;BR /&gt;
group by date and racenum&lt;BR /&gt;
&lt;BR /&gt;
Flip's version is a much better one. You just need to alter it slightly. Instead of deleting records, just keep them.&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table no_zeros as&lt;BR /&gt;
select * from your_dataset&lt;BR /&gt;
where a not in (select distinct a from your_dataset where b=0);&lt;BR /&gt;
quit;</description>
      <pubDate>Tue, 24 Mar 2009 17:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10272#M726</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T17:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10273#M727</link>
      <description>Sorry for the error comment, just ment it wasnt doing what we wanted.  Pznew, your code will do the job now, but if the other is more efficient I would like to give it a shot.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table no_zeros as&lt;BR /&gt;
select * from aptest&lt;BR /&gt;
where date and racenum not in (select distinct date and racenum from aptest where lifestarts = 0);&lt;BR /&gt;
quit; &lt;BR /&gt;
&lt;BR /&gt;
This still does not seem to work.  It just deleted the first racenum of each date.  I think it is selecting a distinct date and then racenum=1 is the first racenum it comes to so it deltes it.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I have not used proc sql so I am kind of lost.  The date, racenum fix from above doesnt work in this setting.</description>
      <pubDate>Tue, 24 Mar 2009 17:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10273#M727</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T17:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10274#M728</link>
      <description>Try where date || racenum not in (select distinct date || racenum from aptest where lifestarts = 0);&lt;BR /&gt;
&lt;BR /&gt;
SQL will often give warnings, but once you understand what is happening, you can usually tell if they are a problem.  Of course if you are validating the system you may need to code so that you do not get them.  ie. creating a new data set or using a work dataset to do the selection.</description>
      <pubDate>Tue, 24 Mar 2009 18:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10274#M728</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-24T18:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10275#M729</link>
      <description>283  proc sql;&lt;BR /&gt;
284  create table no_zeros as&lt;BR /&gt;
285  select * from aptest&lt;BR /&gt;
286  where date || racenum not in (select distinct date || racenum from aptest where lifestarts = 0);&lt;BR /&gt;
ERROR: Concatenation (||) requires character operands.&lt;BR /&gt;
ERROR: Concatenation (||) requires character operands.</description>
      <pubDate>Tue, 24 Mar 2009 18:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10275#M729</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T18:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10276#M730</link>
      <description>Sorry;&lt;BR /&gt;
&lt;BR /&gt;
how about:&lt;BR /&gt;
create table no_zeros as select a.* from aptest as a, (select a,  c from aptest where b=0) as b&lt;BR /&gt;
   where not(a.date = b.date and b.racenum  = a.racenum);</description>
      <pubDate>Tue, 24 Mar 2009 19:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10276#M730</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-24T19:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: delete sets of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10277#M731</link>
      <description>Got it,  Thanks!</description>
      <pubDate>Tue, 24 Mar 2009 19:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-sets-of-observations/m-p/10277#M731</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T19:52:35Z</dc:date>
    </item>
  </channel>
</rss>

