<?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: Rename duplicates and fish out the odds in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535716#M147136</link>
    <description>&lt;P&gt;Here's a proc sql method. The order of the final table is different, but the result is the same:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
length one two $32;
input one two;

datalines;
apple 	fruits
apple 	fruits
apple 	fruits
apple 	fruits
apple 	vegetables
apple 	fruits
artichoke vegetables
artichoke vegetables
asparagus vegetables
asparagus vegetables
broccoli vegetables
broccoli vegetables
carrots vegetables
eggplant vegetables
eggplant fruits
orange fruits
orange fruits
orange fruits
orange fruits
orange fruits
orange fruits
pear vegetables
pear fruits
pear fruits
pear fruits
pear fruits
pear fruits
pepper vegetables
pepper fruits
;;;
run;

proc sql noprint;
	create table want as
	select two_count.one, two_count.two 
	from (select one, count(*) as one_count
		  from temp
		  group by one) as one_count, 
		  (	select one, two, count(*) as count_both
	from temp
	group by one, two) as two_count
	where one_count.one = two_count.one
		and one_count.one_count ne two_count.count_both;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 14 Feb 2019 19:28:11 GMT</pubDate>
    <dc:creator>noling</dc:creator>
    <dc:date>2019-02-14T19:28:11Z</dc:date>
    <item>
      <title>Rename duplicates and fish out the odds</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535685#M147130</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset looks like below:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;apple&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;fruits&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;apple&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;fruits&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;apple&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;fruits&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;apple&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;fruits&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;apple&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;apple&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;fruits&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;artichoke&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;artichoke&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;asparagus&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;asparagus&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;broccoli&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;broccoli&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;carrots&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&g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TD&gt;pepper&lt;/TD&gt;&lt;TD&gt;fruits&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to fish out the items which have been assigned as the wrong category as below&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;apple&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;apple&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;fruits&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;eggplant&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;eggplant&lt;/TD&gt;&lt;TD&gt;fruits&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;pear&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;pear&lt;/TD&gt;&lt;TD&gt;fruits&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;pepper&lt;/TD&gt;&lt;TD&gt;vegetables&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;pepper&lt;/TD&gt;&lt;TD&gt;fruits&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any effective way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks you!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 18:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535685#M147130</guid>
      <dc:creator>zimcom</dc:creator>
      <dc:date>2019-02-14T18:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Rename duplicates and fish out the odds</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535714#M147135</link>
      <description>Plenty of ways... here is one:&lt;BR /&gt;&lt;BR /&gt;proc freq data=have noprint;&lt;BR /&gt;tables food * category / out=counts;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set counts;&lt;BR /&gt;by item;&lt;BR /&gt;if first.item = 0 or last.item = 0;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 14 Feb 2019 19:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535714#M147135</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-14T19:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Rename duplicates and fish out the odds</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535716#M147136</link>
      <description>&lt;P&gt;Here's a proc sql method. The order of the final table is different, but the result is the same:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
length one two $32;
input one two;

datalines;
apple 	fruits
apple 	fruits
apple 	fruits
apple 	fruits
apple 	vegetables
apple 	fruits
artichoke vegetables
artichoke vegetables
asparagus vegetables
asparagus vegetables
broccoli vegetables
broccoli vegetables
carrots vegetables
eggplant vegetables
eggplant fruits
orange fruits
orange fruits
orange fruits
orange fruits
orange fruits
orange fruits
pear vegetables
pear fruits
pear fruits
pear fruits
pear fruits
pear fruits
pepper vegetables
pepper fruits
;;;
run;

proc sql noprint;
	create table want as
	select two_count.one, two_count.two 
	from (select one, count(*) as one_count
		  from temp
		  group by one) as one_count, 
		  (	select one, two, count(*) as count_both
	from temp
	group by one, two) as two_count
	where one_count.one = two_count.one
		and one_count.one_count ne two_count.count_both;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Feb 2019 19:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535716#M147136</guid>
      <dc:creator>noling</dc:creator>
      <dc:date>2019-02-14T19:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Rename duplicates and fish out the odds</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535720#M147138</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/219549" target="_self"&gt;&lt;SPAN class="login-bold"&gt;zimcom&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question is, how will you determine what is correct/incorrect? In your example, you have 2 observations for Eggplant, 1 categorized as Fruit, 1 as Vegetable and is a great example of a fruit that people generally think of as a vegetable (Tomato would be another).&lt;BR /&gt;&lt;BR /&gt;Here's an idea you could use a PROC SUMMARY to view counts, which can be pushed to a SAS Dataset. You could then review the output and determine what is correct/incorrect.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input ;
	input item : $16. category : $16. ;
cards ;

apple 	fruits
apple 	fruits
apple 	fruits
apple 	fruits
apple 	vegetables
apple 	fruits
artichoke	vegetables
artichoke	vegetables
asparagus	vegetables
asparagus	vegetables
broccoli 	vegetables
broccoli 	vegetables
carrots	vegetables
eggplant	vegetables
eggplant	fruits
orange	fruits
orange	fruits
orange	fruits
orange	fruits
orange	fruits
orange	fruits
pear	vegetables
pear	fruits
pear	fruits
pear	fruits
pear	fruits
pear	fruits
pepper	vegetables
pepper	fruits
;
run ;

proc summary print;
	class item category ;
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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 19:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535720#M147138</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2019-02-14T19:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Rename duplicates and fish out the odds</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535725#M147141</link>
      <description>&lt;P&gt;how about something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data foodtypes;&lt;BR /&gt;length food type $ 12;&lt;BR /&gt;input food $ type $;&lt;BR /&gt;datalines;&lt;BR /&gt;apple fruits&lt;BR /&gt;apple fruits&lt;BR /&gt;apple fruits&lt;BR /&gt;apple fruits&lt;BR /&gt;apple vegetables&lt;BR /&gt;apple fruits&lt;BR /&gt;artichoke vegetables&lt;BR /&gt;artichoke vegetables&lt;BR /&gt;asparagus vegetables&lt;BR /&gt;asparagus vegetables&lt;BR /&gt;broccoli vegetables&lt;BR /&gt;broccoli vegetables&lt;BR /&gt;carrots vegetables&lt;BR /&gt;eggplant vegetables&lt;BR /&gt;eggplant fruits&lt;BR /&gt;orange fruits&lt;BR /&gt;orange fruits&lt;BR /&gt;orange fruits&lt;BR /&gt;orange fruits&lt;BR /&gt;orange fruits&lt;BR /&gt;orange fruits&lt;BR /&gt;pear vegetables&lt;BR /&gt;pear fruits&lt;BR /&gt;pear fruits&lt;BR /&gt;pear fruits&lt;BR /&gt;pear fruits&lt;BR /&gt;pear fruits&lt;BR /&gt;pepper vegetables&lt;BR /&gt;pepper fruits&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc freq data=foodtypes noprint;&lt;BR /&gt;tables food*type / out=crosstab;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc freq data=crosstab noprint;&lt;BR /&gt;tables food / out=foodfreq;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data discrepant;&lt;BR /&gt;set foodfreq;&lt;BR /&gt;if count=2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;select "'"||strip(food)||"'" into :FoodList separated by ','&lt;BR /&gt;from discrepant;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;proc print data=crosstab noobs;&lt;BR /&gt;var food type;&lt;BR /&gt;where food in (&amp;amp;foodlist);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 19:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535725#M147141</guid>
      <dc:creator>cminard</dc:creator>
      <dc:date>2019-02-14T19:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Rename duplicates and fish out the odds</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535744#M147144</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/27112"&gt;@cminard&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226241"&gt;@AMSAS&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115150"&gt;@noling&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They all worked, one way or the other, that is the power of SAS and that is the power of programming!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THANK YOU ALL!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 20:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-duplicates-and-fish-out-the-odds/m-p/535744#M147144</guid>
      <dc:creator>zimcom</dc:creator>
      <dc:date>2019-02-14T20:44:43Z</dc:date>
    </item>
  </channel>
</rss>

