<?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: deleting observations in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9633#M724</link>
    <description>[pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data i;&lt;BR /&gt;
  input ID Grade;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 3.2&lt;BR /&gt;
1 3.7&lt;BR /&gt;
1 .&lt;BR /&gt;
1 3.5&lt;BR /&gt;
2 2.7&lt;BR /&gt;
2 4&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want(drop=rc);&lt;BR /&gt;
 declare hash ha (hashexp:10);&lt;BR /&gt;
  ha.definekey('id');&lt;BR /&gt;
  ha.definedone();&lt;BR /&gt;
&lt;BR /&gt;
 do until(last);&lt;BR /&gt;
  set i end=last;&lt;BR /&gt;
  if missing(grade) then rc=ha.add();&lt;BR /&gt;
 end;&lt;BR /&gt;
 do until(_last);&lt;BR /&gt;
  set i end=_last;&lt;BR /&gt;
  rc=ha.check();&lt;BR /&gt;
  if rc ne 0 then output;&lt;BR /&gt;
 end;&lt;BR /&gt;
stop;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Thu, 09 Jun 2011 01:47:24 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-06-09T01:47:24Z</dc:date>
    <item>
      <title>deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9630#M721</link>
      <description>Hi, I am new to SAS and have a basic question. Lets say I have the following table:&lt;BR /&gt;
&lt;BR /&gt;
ID   Grade&lt;BR /&gt;
1        3.2&lt;BR /&gt;
1        3.7&lt;BR /&gt;
1          .&lt;BR /&gt;
1        3.5&lt;BR /&gt;
2        2.7&lt;BR /&gt;
2        4&lt;BR /&gt;
&lt;BR /&gt;
and I need to remove all IDs that have at least one grade missing meaning the final output should be:&lt;BR /&gt;
ID   Grade&lt;BR /&gt;
2      2.7&lt;BR /&gt;
2      4&lt;BR /&gt;
&lt;BR /&gt;
How should I approach this?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Wed, 08 Jun 2011 18:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9630#M721</guid>
      <dc:creator>ab30</dc:creator>
      <dc:date>2011-06-08T18:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9631#M722</link>
      <description>Hello AB30,&lt;BR /&gt;
&lt;BR /&gt;
This is a solution:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data i;&lt;BR /&gt;
  input ID Grade;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 3.2&lt;BR /&gt;
1 3.7&lt;BR /&gt;
1 .&lt;BR /&gt;
1 3.5&lt;BR /&gt;
2 2.7&lt;BR /&gt;
2 4&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=i;&lt;BR /&gt;
  by ID Grade;&lt;BR /&gt;
run;  &lt;BR /&gt;
data r;&lt;BR /&gt;
  retain keep;&lt;BR /&gt;
  set i;&lt;BR /&gt;
  if FIRST.ID               then keep=1;&lt;BR /&gt;
  if FIRST.ID and Grade = . then keep=0; &lt;BR /&gt;
  if keep then output;&lt;BR /&gt;
  by ID;&lt;BR /&gt;
  drop keep;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 08 Jun 2011 19:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9631#M722</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-06-08T19:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9632#M723</link>
      <description>Thanks! Is there a way to do it without sorting the array? (I need to keep the original order)</description>
      <pubDate>Wed, 08 Jun 2011 21:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9632#M723</guid>
      <dc:creator>ab30</dc:creator>
      <dc:date>2011-06-08T21:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9633#M724</link>
      <description>[pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data i;&lt;BR /&gt;
  input ID Grade;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 3.2&lt;BR /&gt;
1 3.7&lt;BR /&gt;
1 .&lt;BR /&gt;
1 3.5&lt;BR /&gt;
2 2.7&lt;BR /&gt;
2 4&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want(drop=rc);&lt;BR /&gt;
 declare hash ha (hashexp:10);&lt;BR /&gt;
  ha.definekey('id');&lt;BR /&gt;
  ha.definedone();&lt;BR /&gt;
&lt;BR /&gt;
 do until(last);&lt;BR /&gt;
  set i end=last;&lt;BR /&gt;
  if missing(grade) then rc=ha.add();&lt;BR /&gt;
 end;&lt;BR /&gt;
 do until(_last);&lt;BR /&gt;
  set i end=_last;&lt;BR /&gt;
  rc=ha.check();&lt;BR /&gt;
  if rc ne 0 then output;&lt;BR /&gt;
 end;&lt;BR /&gt;
stop;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Thu, 09 Jun 2011 01:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9633#M724</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-06-09T01:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9634#M725</link>
      <description>To get the file back into original order, you can capture _N_ as your variable (choose a name like OBSNUM) and then the last task in your SAS program would be to re-sort the file back into its original sequence using OBSNUM.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 09 Jun 2011 10:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9634#M725</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-06-09T10:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9635#M726</link>
      <description>Yes.That is a good way.&lt;BR /&gt;
But If you have a large dataset?which will waste lots of time.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 10 Jun 2011 01:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9635#M726</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-06-10T01:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: deleting observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9636#M727</link>
      <description>Just to add some variety, you can modify your input data as suggested by sbb and then use a proc sql step to generate your table.&lt;BR /&gt;
&lt;BR /&gt;
data grades;&lt;BR /&gt;
  input id grade;&lt;BR /&gt;
  obs = _n_;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 3.2&lt;BR /&gt;
1 3.7&lt;BR /&gt;
1 .&lt;BR /&gt;
1 3.5&lt;BR /&gt;
2 2.7&lt;BR /&gt;
2 4&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table grades2 as&lt;BR /&gt;
  select id, grade&lt;BR /&gt;
  from grades&lt;BR /&gt;
  group by id &lt;BR /&gt;
  having sum(grade=.)=0&lt;BR /&gt;
  order by obs;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Rich</description>
      <pubDate>Fri, 17 Jun 2011 00:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/deleting-observations/m-p/9636#M727</guid>
      <dc:creator>rtritz</dc:creator>
      <dc:date>2011-06-17T00:45:24Z</dc:date>
    </item>
  </channel>
</rss>

