<?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: Finding invalid ID numbers in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Finding-invalid-ID-numbers/m-p/33718#M8164</link>
    <description>En.Yes .SAS can do it.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
 infile datalines delimiter=' ,';&lt;BR /&gt;
 input parentid	$ subid $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
123, 990&lt;BR /&gt;
123, 991&lt;BR /&gt;
124, 992&lt;BR /&gt;
124, 990&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql feedback;&lt;BR /&gt;
 select *&lt;BR /&gt;
  from temp&lt;BR /&gt;
   group by subid&lt;BR /&gt;
    having count(distinct parentid ) ge 2;&lt;BR /&gt;
	quit;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Mon, 15 Nov 2010 07:08:33 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2010-11-15T07:08:33Z</dc:date>
    <item>
      <title>Finding invalid ID numbers</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-invalid-ID-numbers/m-p/33717#M8163</link>
      <description>I hope this is the correct place for this posting.  My problem may be better solved within a DATA step.&lt;BR /&gt;
&lt;BR /&gt;
I have a table with two different ID fields:  ParentID and SubID.  In this table, ParentID is not unique.  SubID is not unique either, and any one ParentID may be associated with multiple SubIDs.  However, no SubID should appear for more than one different ParentID.  But there are some records scattered in my table where this occurs, and I need to find them.&lt;BR /&gt;
&lt;BR /&gt;
So this table would be fine if it looked like this:&lt;BR /&gt;
ParentID, SubID&lt;BR /&gt;
123, 990&lt;BR /&gt;
123, 991&lt;BR /&gt;
124, 992&lt;BR /&gt;
124, 992&lt;BR /&gt;
&lt;BR /&gt;
But this table would NOT be ok, because SubID 990 occurs for two different ParentIDs:&lt;BR /&gt;
ParentID, SubID&lt;BR /&gt;
123, 990&lt;BR /&gt;
123, 991&lt;BR /&gt;
124, 992&lt;BR /&gt;
124, 990&lt;BR /&gt;
&lt;BR /&gt;
My table has thousands of records, so eyeballing the data is not an option.  How can I find the records with a SubID that appears for more than one ParentID, with SAS code?&lt;BR /&gt;
&lt;BR /&gt;
Thank you,&lt;BR /&gt;
Brett</description>
      <pubDate>Mon, 15 Nov 2010 04:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-invalid-ID-numbers/m-p/33717#M8163</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-15T04:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: Finding invalid ID numbers</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-invalid-ID-numbers/m-p/33718#M8164</link>
      <description>En.Yes .SAS can do it.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
 infile datalines delimiter=' ,';&lt;BR /&gt;
 input parentid	$ subid $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
123, 990&lt;BR /&gt;
123, 991&lt;BR /&gt;
124, 992&lt;BR /&gt;
124, 990&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql feedback;&lt;BR /&gt;
 select *&lt;BR /&gt;
  from temp&lt;BR /&gt;
   group by subid&lt;BR /&gt;
    having count(distinct parentid ) ge 2;&lt;BR /&gt;
	quit;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 15 Nov 2010 07:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-invalid-ID-numbers/m-p/33718#M8164</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-11-15T07:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Finding invalid ID numbers</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-invalid-ID-numbers/m-p/33719#M8165</link>
      <description>Since you are looking for unique or distinct parents within subjects, there will be multiple solutions.  Here is a DATA step solution, but it requires a SORT and therefore more passes of the data than does KSharp's solution.&lt;BR /&gt;
[pre]data id;&lt;BR /&gt;
infile datalines dlm=',';&lt;BR /&gt;
input parentid subjid;&lt;BR /&gt;
datalines;&lt;BR /&gt;
123, 990&lt;BR /&gt;
123, 991&lt;BR /&gt;
124, 992&lt;BR /&gt;
124, 990&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=id nodupkey;&lt;BR /&gt;
   by subjid parentid;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
* parents should be unique within subjects;&lt;BR /&gt;
data goodid&lt;BR /&gt;
      badid;&lt;BR /&gt;
   set id;&lt;BR /&gt;
   by subjid;&lt;BR /&gt;
   if not (first.subjid and last.subjid) then output badid;&lt;BR /&gt;
   else output goodid;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
title good id;&lt;BR /&gt;
proc print data=goodid;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
title bad id;&lt;BR /&gt;
proc print data=badid;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 15 Nov 2010 07:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-invalid-ID-numbers/m-p/33719#M8165</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-11-15T07:23:06Z</dc:date>
    </item>
  </channel>
</rss>

