<?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 inconsistencies within a group in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841691#M82182</link>
    <description>Thank you so much KSharp!!  I so appreciate your help.   This was exactly what I was looking for.   thank you again!</description>
    <pubDate>Mon, 31 Oct 2022 16:10:47 GMT</pubDate>
    <dc:creator>SannaSanna</dc:creator>
    <dc:date>2022-10-31T16:10:47Z</dc:date>
    <item>
      <title>Finding inconsistencies within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841483#M82170</link>
      <description>&lt;P&gt;Hi.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a very large dataset and I need to be able to locate data discrepancies to exclude from my rate calculation.&amp;nbsp; In my example below, column Verd1 is the main identifier and column LocalVerd is another identifier created by a vendor.&amp;nbsp; I need to figure out how to code to identify erroneous data within a group.&amp;nbsp; In the example below, under column Plan, Pacific would pass and is correct as the rows within Pacific contain consistent identifier information (Same Verd1 and same localVerd).&amp;nbsp; However, Plan Delta for product X33ui will need to be excluded as this product (X33ui) contain two different LocalVerd identifiers (PX333 and Rx988) for this same Verd1 identifier (Twa88)- LocalVerd should be PX333 but reported Rx988. &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to code to output table containing all the Plan and product containing inconsistencies?&amp;nbsp; &amp;nbsp; Data table is below and my output table I would like is the second table.&amp;nbsp; Thank you in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="256"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;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;
&lt;TR&gt;
&lt;TD&gt;Plan&lt;/TD&gt;
&lt;TD&gt;Product&lt;/TD&gt;
&lt;TD&gt;Verd1&lt;/TD&gt;
&lt;TD&gt;LocalVerd&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Delta&lt;/TD&gt;
&lt;TD&gt;X33ui&lt;/TD&gt;
&lt;TD&gt;Twa88&lt;/TD&gt;
&lt;TD&gt;PX333&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Delta&lt;/TD&gt;
&lt;TD&gt;X33ui&lt;/TD&gt;
&lt;TD&gt;Twa88&lt;/TD&gt;
&lt;TD&gt;PX333&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Delta&lt;/TD&gt;
&lt;TD&gt;X33ui&lt;/TD&gt;
&lt;TD&gt;Twa88&lt;/TD&gt;
&lt;TD&gt;RX988&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 20:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841483#M82170</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2022-10-29T20:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Finding inconsistencies within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841501#M82171</link>
      <description>&lt;P&gt;If the data are already grouiped by VERD1, then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=n_local_changes);

  do n_local_changes=0 by 1 until (last.verd1);
    do until (last.localverd);
      set have;
      by verd1 localverd notsorted;
    end;
  end;

  do until (last.verd1;
    set have;
    by verd1;
    if n_local_changes&amp;gt;0;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This counts the number of times the value of localverd changes within a given VERD1.&amp;nbsp; It's not necessarily the cardinality of localverd, unless the data within a verd1 is grouped by localverd.&amp;nbsp; Arter the change count is calculated, the verd1 group is re-read, and output if the count is at least 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2022 02:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841501#M82171</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-10-30T02:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding inconsistencies within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841502#M82172</link>
      <description>&lt;P&gt;Going forward many people appreciate if the one asking the question provides sample data via a fully working SAS data step like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input (Plan Product Verd1 LocalVerd) ($);
  datalines;
Delta X33ui Twa88 PX333
Delta X33ui Twa88 PX333
Delta X33ui Twa88 RX988
Pacific V933aa Lbl322 QT770
Pacific V933aa Lbl322 QT770
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here some code using the sample data created above that hopefully does what you're after or then at least points you into the right direction.&lt;/P&gt;
&lt;P&gt;If you're just after the distinct list of rows with inconsistencies then you don't need the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort 
  data=have(keep=Plan Product Verd1 LocalVerd)
  out=_inter 
  nodupkey;
  by Plan Verd1 LocalVerd Product;
run;

proc sort data=_inter out=one_row_per_discrepancy nounikey;
  by Plan Verd1;
run;

data all_rows_discrepancies all_rows_ok;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'one_row_per_discrepancy');
      h1.defineKey(all:'y');
      h1.defineDone();
    end;
  set have;
  if h1.check()=0 then output all_rows_discrepancies;
  else output all_rows_ok;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2022 02:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841502#M82172</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-10-30T02:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Finding inconsistencies within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841506#M82174</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input (Plan Product Verd1 LocalVerd) ($);
  datalines;
Delta X33ui Twa88 PX333
Delta X33ui Twa88 PX333
Delta X33ui Twa88 RX988
Pacific V933aa Lbl322 QT770
Pacific V933aa Lbl322 QT770
;

proc sql;
create table want as
select *
 from have
  group by plan,product
   having count(distinct cats(Verd1,LocalVerd))&amp;gt;1 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 30 Oct 2022 09:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841506#M82174</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-10-30T09:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Finding inconsistencies within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841690#M82181</link>
      <description>thank you.  This works but the results KSharp code provided below is what I am after.  Thank you so much for your help!</description>
      <pubDate>Mon, 31 Oct 2022 16:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841690#M82181</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2022-10-31T16:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: Finding inconsistencies within a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841691#M82182</link>
      <description>Thank you so much KSharp!!  I so appreciate your help.   This was exactly what I was looking for.   thank you again!</description>
      <pubDate>Mon, 31 Oct 2022 16:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Finding-inconsistencies-within-a-group/m-p/841691#M82182</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2022-10-31T16:10:47Z</dc:date>
    </item>
  </channel>
</rss>

