<?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: Keeing ONE address in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555611#M74722</link>
    <description>&lt;P&gt;There are some tricky situations to consider, both in the planning and execution.&amp;nbsp; Not all solutions will return the same result for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Client_ID	Address
ABC123	11 East Street, City1, OH
ABC123	11 East Street, City1, OH County 5
ABC123	11 East Street, City1, OH County 5&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And what would you like the result to be in cases of a tie?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Client_ID	Address
ABC123	11 East Street, City1, OH
ABC123	11 East Street, City1, OH County 4
ABC123	11 East Street, City1, OH County 5&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 May 2019 13:41:03 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-05-02T13:41:03Z</dc:date>
    <item>
      <title>Keeing ONE address</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555595#M74719</link>
      <description>&lt;P&gt;Greetings Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Client_ID&lt;/TD&gt;&lt;TD&gt;Address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC123&lt;/TD&gt;&lt;TD&gt;11 East Street, City1, OH&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC123&lt;/TD&gt;&lt;TD&gt;11 East Street, City1, OH County 5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XFE51D&lt;/TD&gt;&lt;TD&gt;100 Main Street, City2, OH&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XFE51D&lt;/TD&gt;&lt;TD&gt;100 Main Street, City2, OH&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to keep only ONE observation for each client with the following conditions:&lt;/P&gt;&lt;P&gt;- If the addresses are different, keep the longest address&lt;/P&gt;&lt;P&gt;- if the addresses are the same, keep only one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My final dataset should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Client_ID&lt;/TD&gt;&lt;TD&gt;Address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC123&lt;/TD&gt;&lt;TD&gt;11 East Street, City1, OH County 5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XFE51D&lt;/TD&gt;&lt;TD&gt;100 Main Street, City2, OH&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 13:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555595#M74719</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2019-05-02T13:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Keeing ONE address</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555602#M74720</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Client_ID $	Address $50.;
cards;
ABC123	11 East Street, City1, OH
ABC123	11 East Street, City1, OH County 5
XFE51D	100 Main Street, City2, OH
XFE51D	100 Main Street, City2, OH
;

proc sql;
create table want  as
select distinct *
from have
group by client_id
having max(length(address))=length(address);
quit;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2019 13:41:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555602#M74720</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-02T13:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Keeing ONE address</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555606#M74721</link>
      <description>&lt;P&gt;If you want to use LENGTH as a criteria you need to add it to your dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  a_length=length(address);
run;

proc sort;
  by client_id a_length;
run;

data want;
  set want;
  by client_id;
  if last.client_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2019 13:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555606#M74721</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-02T13:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: Keeing ONE address</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555611#M74722</link>
      <description>&lt;P&gt;There are some tricky situations to consider, both in the planning and execution.&amp;nbsp; Not all solutions will return the same result for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Client_ID	Address
ABC123	11 East Street, City1, OH
ABC123	11 East Street, City1, OH County 5
ABC123	11 East Street, City1, OH County 5&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And what would you like the result to be in cases of a tie?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Client_ID	Address
ABC123	11 East Street, City1, OH
ABC123	11 East Street, City1, OH County 4
ABC123	11 East Street, City1, OH County 5&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2019 13:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555611#M74722</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-02T13:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Keeing ONE address</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555662#M74724</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;There are some tricky situations to consider, both in the planning and execution.&amp;nbsp; Not all solutions will return the same result for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Client_ID	Address
ABC123	11 East Street, City1, OH
ABC123	11 East Street, City1, OH County 5
ABC123	11 East Street, City1, OH County 5&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And what would you like the result to be in cases of a tie?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Client_ID	Address
ABC123	11 East Street, City1, OH
ABC123	11 East Street, City1, OH County 4
ABC123	11 East Street, City1, OH County 5&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or even more fun&lt;/P&gt;
&lt;PRE&gt;Client_ID Address 
ABC123 11 East Street, City1, OH County 4 
ABC123 22 West Street, Abcde, OH OCount 9
&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2019 17:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555662#M74724</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-02T17:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Keeing ONE address</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555889#M74725</link>
      <description>&lt;P&gt;Ballardw&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for bringing that up. All these&amp;nbsp;combinations are possible. I have an additional column in the data that has the Date of that record. In case of any of these possibilities,&amp;nbsp;I need to pick&amp;nbsp;up the latest address (based on the most recent Date).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Client_ID Address&amp;nbsp; Date&lt;BR /&gt;ABC123 &lt;SPAN class="token number"&gt;11&lt;/SPAN&gt; East Street&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; City1&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; OH&amp;nbsp; 05/01/2018&lt;BR /&gt;ABC123 &lt;SPAN class="token number"&gt;11&lt;/SPAN&gt; East Street&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; City1&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; OH County &lt;SPAN class="token number"&gt;5 09/09/2018&lt;/SPAN&gt;&lt;BR /&gt;ABC123 &lt;SPAN class="token number"&gt;11&lt;/SPAN&gt; East Street&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; City1&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; OH County &lt;SPAN class="token number"&gt;5 01/13/2019&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How the code will look like now?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 11:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/555889#M74725</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2019-05-03T11:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Keeing ONE address</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/556129#M74729</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130872"&gt;@altijani&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Ballardw&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for bringing that up. All these&amp;nbsp;combinations are possible. I have an additional column in the data that has the Date of that record. In case of any of these possibilities,&amp;nbsp;I need to pick&amp;nbsp;up the latest address (based on the most recent Date).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the data looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Client_ID Address&amp;nbsp; Date&lt;BR /&gt;ABC123 &lt;SPAN class="token number"&gt;11&lt;/SPAN&gt; East Street&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; City1&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; OH&amp;nbsp; 05/01/2018&lt;BR /&gt;ABC123 &lt;SPAN class="token number"&gt;11&lt;/SPAN&gt; East Street&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; City1&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; OH County &lt;SPAN class="token number"&gt;5 09/09/2018&lt;/SPAN&gt;&lt;BR /&gt;ABC123 &lt;SPAN class="token number"&gt;11&lt;/SPAN&gt; East Street&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; City1&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; OH County &lt;SPAN class="token number"&gt;5 01/13/2019&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How the code will look like now?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When I have dated addresses I would just take the latest. Unless you have lots of duplicate dates with different addresses then this should work if your date variable is an actual SAS date value (numeric with a SAS format like mmddyy10.)&lt;/P&gt;
&lt;PRE&gt;Proc sort data=have;
   by client_id date;
run;

data want;
   set have;
   by client_id;
   if last.client_id;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 May 2019 23:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/556129#M74729</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-03T23:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Keeing ONE address</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/556130#M74730</link>
      <description>&lt;P&gt;It sounds like you are looking for the longest value, but using DATE to break ties.&amp;nbsp; I have to assume that you know what a SAS date actually should contain, and that your data actually contains true SAS dates.&amp;nbsp; In that case, I would choose a variation on a method that was suggested earlier:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  a_length=length(address);
run;

proc sort;
  by client_id a_length date;
run;

data want;
  set want;
  by client_id;
  if last.client_id;&lt;BR /&gt;  drop a_length;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 May 2019 23:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/556130#M74730</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-03T23:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Keeing ONE address</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/556386#M74743</link>
      <description>Thank you</description>
      <pubDate>Mon, 06 May 2019 11:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Keeing-ONE-address/m-p/556386#M74743</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2019-05-06T11:34:46Z</dc:date>
    </item>
  </channel>
</rss>

