<?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: Conditionally remove missing values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930616#M41859</link>
    <description>&lt;P&gt;Since you are treating 0002 as numeric, simply counting will get you the answer. Did you really want them to be treated as numeric?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select * from DB
    group by id
    having count(id2)&amp;gt;0 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=db nway;
    class id;
    var id2;
    output out=stats n=n_not_missing;
run;
data want;
    merge db stats;
    by id;
    if n_not_missing&amp;gt;0;
    drop _type_ _freq_ n_not_missing;
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;If you want to preserve the order in the original data set, the SQL doesn't do that but the PROC SUMMARY solution does.&lt;/P&gt;</description>
    <pubDate>Mon, 03 Jun 2024 15:42:15 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-06-03T15:42:15Z</dc:date>
    <item>
      <title>Conditionally remove missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930610#M41855</link>
      <description>&lt;P&gt;Hi guys, suppose to have the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID ID2;
cards;
0001   .
0001   .
0001   .
0001   .
0002   .
0002  0002
0002  0002
0003  0003
0003   .
...;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Is there a way to get the following?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input ID ID2;
cards;
0002   .
0002  0002
0002  0002
0003  0003
0003   .
...;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words if an ID is absent in column ID2 then delete. I tried with if statement without success maybe because there are other missing values in ID2. Can anyone help me please?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 15:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930610#M41855</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-06-03T15:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally remove missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930615#M41858</link>
      <description>&lt;P&gt;Hash Tables can help here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID ID2;
cards;
0001   .
0001   .
0001   .
0001   .
0002   .
0002  0002
0002  0002
0003  0003
0003   .
;
run;
proc print;run;

data want;

declare hash H(dataset:"DB(keep=ID2 where=(ID2 is not null))");
H.defineKey('ID2');
H.defineDone();

do until (EOF);
  set db end=EOF;
  if 0 = H.check(key:ID) then output;
end;

stop;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 15:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930615#M41858</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-06-03T15:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally remove missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930616#M41859</link>
      <description>&lt;P&gt;Since you are treating 0002 as numeric, simply counting will get you the answer. Did you really want them to be treated as numeric?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select * from DB
    group by id
    having count(id2)&amp;gt;0 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=db nway;
    class id;
    var id2;
    output out=stats n=n_not_missing;
run;
data want;
    merge db stats;
    by id;
    if n_not_missing&amp;gt;0;
    drop _type_ _freq_ n_not_missing;
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;If you want to preserve the order in the original data set, the SQL doesn't do that but the PROC SUMMARY solution does.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 15:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930616#M41859</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-06-03T15:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally remove missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930751#M41868</link>
      <description>proc sql;&lt;BR /&gt;    create table want as select * from DB&lt;BR /&gt;      where id in (select id from DB where ID2 is not missing) ;&lt;BR /&gt;quit;</description>
      <pubDate>Tue, 04 Jun 2024 02:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930751#M41868</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-06-04T02:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally remove missing values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930837#M41880</link>
      <description>&lt;P&gt;Sounds like you mean that you are keeping those observations because the value of ID appears at some point in the value of ID2.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as select a.*
from have a 
where a.id in (select b.id2 from have b where b.id2 is not null)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the example data you showed also supports the more restrictive condition that you are keeping those observations because at some point in the subset of observations with that same value of ID there exists an observation where ID2 matches ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want2 as select a.*
from have a 
where a.id in (select b.id2 from have b where b.id=b.id2 and b.id2 is not null)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jun 2024 16:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-remove-missing-values/m-p/930837#M41880</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-04T16:25:05Z</dc:date>
    </item>
  </channel>
</rss>

