<?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 group in SAS if all observations are missing in that group for a column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821420#M324294</link>
    <description>&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
  create table want as
  select *
  from have
  where cats(ric) not in 
  (select cats(ric) from have where n =.);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I didn't tested may be you can for this approach.&lt;/P&gt;</description>
    <pubDate>Sun, 03 Jul 2022 13:44:07 GMT</pubDate>
    <dc:creator>Spintu</dc:creator>
    <dc:date>2022-07-03T13:44:07Z</dc:date>
    <item>
      <title>delete group in SAS if all observations are missing in that group for a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821415#M324291</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;The following is an example of my dataset.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
    input ric $ price n;
datalines;
abc 5 .
abc 6 .
bcd 100 10
efg 30 20 
cba 40 10
hba 10 10 
hba 12 . 
cab 6 20
cab 7 20
run;&lt;/PRE&gt;&lt;P&gt;I would like to remove the ric group when all the n for the ric is missing. For example, abc should be removed but not hba (not all n is missing).&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output would look like the following-&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want;
input ric $ price n;
datalines;
bcd 100 10
efg 30 20 
cba 40 10
hba 10 10 
hba 12 . 
cab 6 20
cab 7 20
run;&lt;/PRE&gt;&lt;P&gt;This is my first post. Any help is appreciated. Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jul 2022 13:06:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821415#M324291</guid>
      <dc:creator>nonlinear999</dc:creator>
      <dc:date>2022-07-03T13:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: delete group in SAS if all observations are missing in that group for a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821419#M324293</link>
      <description>&lt;P&gt;I actually solved it. Someone may find it useful. This is the code that I have adapted (reference&amp;nbsp;&lt;A title="reference code" href="https://communities.sas.com/t5/SAS-Programming/how-to-delete-a-group-of-observations-based-on-certain/td-p/496400" target="_self"&gt;community link&lt;/A&gt;&amp;nbsp;)&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want;
set have;
by ric;
retain flag;
if first.ric then call missing(flag);
if first.ric and n^=. then flag=1;
if flag;
drop flag;
run;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jul 2022 13:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821419#M324293</guid>
      <dc:creator>nonlinear999</dc:creator>
      <dc:date>2022-07-03T13:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: delete group in SAS if all observations are missing in that group for a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821420#M324294</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
  create table want as
  select *
  from have
  where cats(ric) not in 
  (select cats(ric) from have where n =.);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I didn't tested may be you can for this approach.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jul 2022 13:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821420#M324294</guid>
      <dc:creator>Spintu</dc:creator>
      <dc:date>2022-07-03T13:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: delete group in SAS if all observations are missing in that group for a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821421#M324295</link>
      <description>&lt;P&gt;That is not a general solution.&amp;nbsp; It worked for your sample because non of the groups to be kept had a missing value on the first observations, just on later observations.&lt;/P&gt;
&lt;P&gt;If you sorted&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by ric descending n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then your logic would work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general you need to check all of the observations in the group before deciding whether or not to delete the observations for that group.&lt;/P&gt;
&lt;P&gt;You could use SQL code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select * from have
  group by ric
  having not missing(max(n))
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if the data is sorted a double DOW loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until (last.ric);
     set have;
     by ric;
     if not missing(n) then flag=1;
  end;
  do until (last.ric);
     set have;
     by ric;
     if flag then output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jul 2022 15:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821421#M324295</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-03T15:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: delete group in SAS if all observations are missing in that group for a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821423#M324296</link>
      <description>&lt;P&gt;I find it easiest to identify the values in a separate step, then merge to include or exclude the ones you want. Here is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sort data=have;
  by ric;

** Select all distinct values of ric that have at least one nonmissing value for n **;
proc sort data=have (where=(^missing(n))) out=nonmissing (keep=ric) nodupkey;
  by ric;

** Restrict 'have' to only include those ric values with at least one nonmissing value for n **;
data want;
  merge have (in=in1)
        nonmissing (in=in2)
        ;
  by ric;
  ** Technically you only need 'in2' here, but as a general practice I like to be explicit with these statements **;
  if in1 &amp;amp; in2;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jul 2022 17:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821423#M324296</guid>
      <dc:creator>qatman28</dc:creator>
      <dc:date>2022-07-03T17:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: delete group in SAS if all observations are missing in that group for a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821425#M324297</link>
      <description>&lt;P&gt;As others have said, there could be RIC groups, in which all obs except the last are missing.&amp;nbsp; Such an RIC should be kept, according to your criteria.&amp;nbsp; But &lt;EM&gt;&lt;STRONG&gt;you have to read the entire RIC group&lt;/STRONG&gt;&lt;/EM&gt; to determine that outcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program below does that.&amp;nbsp; It then rereads each group and outputs it depending on the results of the first pass of the RIC group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  data have;
    input ric $ price n;
datalines;
abc 5 .
abc 6 .
bcd 100 10
efg 30 20 
cba 40 10
hba 10 10 
hba 12 . 
cab 6 20
cab 7 20
run;

data want (drop=_:);
  do until (last.ric);
    set have;
    by ric notsorted;
    if n^=. then _keepdummy=1;
  end;
  do until (last.ric);
    set have;
    by ric notsorted;
    if _keepdummy=1 then output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jul 2022 18:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821425#M324297</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-07-03T18:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: delete group in SAS if all observations are missing in that group for a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821748#M324428</link>
      <description>&lt;P&gt;So this makes more sense and the code seems to work well. You are right (I have missed that part in my explanation). Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 23:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-group-in-SAS-if-all-observations-are-missing-in-that/m-p/821748#M324428</guid>
      <dc:creator>nonlinear999</dc:creator>
      <dc:date>2022-07-05T23:42:47Z</dc:date>
    </item>
  </channel>
</rss>

