<?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 How do i do complex by group processing? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-do-complex-by-group-processing/m-p/451395#M283823</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question regarding the table below (code used to generate it is at bottom of page). My objective is to do a deduplication by email based on the conditions below:&lt;/P&gt;&lt;P&gt;- if there are repeating values of email, priority is given to the origin with the highest rank (where 1=highest , 3=lowest);&lt;/P&gt;&lt;P&gt;- If an email with a rank of 1 is picked over one with a rank of 2, create another data set with a new variable - REASON -&amp;nbsp;dropped since email exist in Europe:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-04-05 at 04.37.36.png" style="width: 237px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19634i625451DF8E61F055/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-04-05 at 04.37.36.png" alt="Screen Shot 2018-04-05 at 04.37.36.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So the two output tables are desired. One contained the emails picked and another containing the emails dropped as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-04-05 at 04.45.15.png" style="width: 254px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19636iF58942B2C9441AF0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-04-05 at 04.45.15.png" alt="Screen Shot 2018-04-05 at 04.45.15.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-04-05 at 04.54.08.png" style="width: 368px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19637i7DF5B6122478ACF7/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-04-05 at 04.54.08.png" alt="Screen Shot 2018-04-05 at 04.54.08.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here are the steps I have taken to get this done:&lt;/P&gt;&lt;P&gt;- sort by email and rank&lt;/P&gt;&lt;P&gt;- then output first record only for each by group&lt;/P&gt;&lt;P&gt;Codes used are below: But how do I create the desired drop out reason table above please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=t1;&lt;BR /&gt;by email rank;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data t2;&lt;BR /&gt;set t1;&lt;BR /&gt;by email rank;&lt;BR /&gt;if first.email;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been able to create the first desired table above but dont know how to go about creating the drop out reason table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please any ideas will help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code to generate the&amp;nbsp;example data set is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data t1;&lt;BR /&gt;length email $18 origin $8;&lt;BR /&gt;input email $ rank origin $;&lt;BR /&gt;datalines;&lt;BR /&gt;llp@lit.com 2 Canada&lt;BR /&gt;llp@lit.com 1 Europe&lt;BR /&gt;llp@lit.com 3 USA&lt;BR /&gt;brin@yahoo.com 3 USA&lt;BR /&gt;brin@yahoo.com 2 Canada&lt;BR /&gt;admin@gmail.com 2 Canada&lt;BR /&gt;admin@gmail.com 3 USA&lt;BR /&gt;;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Apr 2018 04:04:48 GMT</pubDate>
    <dc:creator>ClareRobin1</dc:creator>
    <dc:date>2018-04-05T04:04:48Z</dc:date>
    <item>
      <title>How do i do complex by group processing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-do-complex-by-group-processing/m-p/451395#M283823</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question regarding the table below (code used to generate it is at bottom of page). My objective is to do a deduplication by email based on the conditions below:&lt;/P&gt;&lt;P&gt;- if there are repeating values of email, priority is given to the origin with the highest rank (where 1=highest , 3=lowest);&lt;/P&gt;&lt;P&gt;- If an email with a rank of 1 is picked over one with a rank of 2, create another data set with a new variable - REASON -&amp;nbsp;dropped since email exist in Europe:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-04-05 at 04.37.36.png" style="width: 237px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19634i625451DF8E61F055/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-04-05 at 04.37.36.png" alt="Screen Shot 2018-04-05 at 04.37.36.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So the two output tables are desired. One contained the emails picked and another containing the emails dropped as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-04-05 at 04.45.15.png" style="width: 254px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19636iF58942B2C9441AF0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-04-05 at 04.45.15.png" alt="Screen Shot 2018-04-05 at 04.45.15.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-04-05 at 04.54.08.png" style="width: 368px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19637i7DF5B6122478ACF7/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-04-05 at 04.54.08.png" alt="Screen Shot 2018-04-05 at 04.54.08.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here are the steps I have taken to get this done:&lt;/P&gt;&lt;P&gt;- sort by email and rank&lt;/P&gt;&lt;P&gt;- then output first record only for each by group&lt;/P&gt;&lt;P&gt;Codes used are below: But how do I create the desired drop out reason table above please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=t1;&lt;BR /&gt;by email rank;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data t2;&lt;BR /&gt;set t1;&lt;BR /&gt;by email rank;&lt;BR /&gt;if first.email;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been able to create the first desired table above but dont know how to go about creating the drop out reason table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please any ideas will help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code to generate the&amp;nbsp;example data set is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data t1;&lt;BR /&gt;length email $18 origin $8;&lt;BR /&gt;input email $ rank origin $;&lt;BR /&gt;datalines;&lt;BR /&gt;llp@lit.com 2 Canada&lt;BR /&gt;llp@lit.com 1 Europe&lt;BR /&gt;llp@lit.com 3 USA&lt;BR /&gt;brin@yahoo.com 3 USA&lt;BR /&gt;brin@yahoo.com 2 Canada&lt;BR /&gt;admin@gmail.com 2 Canada&lt;BR /&gt;admin@gmail.com 3 USA&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 04:04:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-do-complex-by-group-processing/m-p/451395#M283823</guid>
      <dc:creator>ClareRobin1</dc:creator>
      <dc:date>2018-04-05T04:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do i do complex by group processing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-do-complex-by-group-processing/m-p/451401#M283824</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE(index=(A=(EMAIL RANK )));
  length EMAIL $18 ;
  input EMAIL $ RANK ORIGIN $;
datalines;
llp@lit.com 2 Canada
llp@lit.com 1 Europe
llp@lit.com 3 USA
brin@yahoo.com 3 USA
brin@yahoo.com 2 Canada
admin@gmail.com 2 Canada
admin@gmail.com 3 USA
run;
data PICKED(drop=REASON) DROPPED;
  set HAVE;
  by EMAIL ;
  length REASON $20;
  retain REASON;
  if first.EMAIL then do;
    REASON='Already in '||ORIGIN;
    output PICKED;
  end;
  else output DROPPED;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE width="253"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="125"&gt;EMAIL&lt;/TD&gt;
&lt;TD width="64"&gt;RANK&lt;/TD&gt;
&lt;TD width="64"&gt;ORIGIN&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;admin@gmail.com&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;Canada&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;brin@yahoo.com&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;Canada&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;llp@lit.com&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Europe&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="432"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="125"&gt;EMAIL&lt;/TD&gt;
&lt;TD width="64"&gt;RANK&lt;/TD&gt;
&lt;TD width="64"&gt;ORIGIN&lt;/TD&gt;
&lt;TD width="179"&gt;REASON&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;admin@gmail.com&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;USA&lt;/TD&gt;
&lt;TD&gt;Already in Canada&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;brin@yahoo.com&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;USA&lt;/TD&gt;
&lt;TD&gt;Already in Canada&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;llp@lit.com&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;Canada&lt;/TD&gt;
&lt;TD&gt;Already in Europe&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;llp@lit.com&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;USA&lt;/TD&gt;
&lt;TD&gt;Already in Europe&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 04:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-do-complex-by-group-processing/m-p/451401#M283824</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-04-05T04:47:58Z</dc:date>
    </item>
  </channel>
</rss>

