<?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: Retain a value from previous obsevation by comparing first 10 characters of address field... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701429#M214802</link>
    <description>&lt;P&gt;Flag the previous record (old sub_date) as duplicate to delete it later.&lt;/P&gt;&lt;P&gt;Then my final data will be clean with one record per unit_name/addr1&lt;/P&gt;</description>
    <pubDate>Wed, 25 Nov 2020 03:24:18 GMT</pubDate>
    <dc:creator>Stalk</dc:creator>
    <dc:date>2020-11-25T03:24:18Z</dc:date>
    <item>
      <title>Retain a value from previous obsevation by comparing first 10 characters of address field...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701406#M214786</link>
      <description>&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;I have a dataset with thousands of rows and about 45&amp;nbsp;columns and I need to clean up the duplicates.I was able to identify dedups but the challenging part is ADDR1 field. I want to compare the first few characters of the ADDR1 field from&amp;nbsp;the previous&amp;nbsp;sub_date to recent sub_date, and if they are closely matching(at least 90%) then I want to retain the previous ADDR1 value to the most recent record. When the ADDR1 field match then I would like to delete the old sub_date record. Is this possible?&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;to_clean ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; sub_date &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;$10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Unit_Name $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;100&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; ADDR1 $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;100;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cards &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;dsd&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;dlm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'|'&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;truncover&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; sub_date -- ADDR1 ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;11/21/2020|BAIRD HUDSON ENTERPRISES|106 E MAIN&lt;/P&gt;&lt;P&gt;10/30/2020|BAIRD HUDSON ENTERPRISES|106 E MAIN STREET&lt;/P&gt;&lt;P&gt;10/30/2020|BIG HORN ENTERPRISE|146 S. BENT STREET&lt;/P&gt;&lt;P&gt;10/30/2020|BIG HORN ENTERPRISE|641 WARREN STREET&lt;/P&gt;&lt;P&gt;11/5/2020|BROOKDALE |&lt;/P&gt;&lt;P&gt;10/29/2020|BROOKDALE|2401 COUGAR AVENUE&lt;/P&gt;&lt;P&gt;10/30/2020|ELMCROFT|1551 SUGARLAND DRIVE&lt;/P&gt;&lt;P&gt;11/2/2020|ELMCROFT|1551 SUGARLAND DRIVE DRIVE&lt;/P&gt;&lt;P&gt;11/21/2020|GREEN HOUSE LIVING|2311 SHIRLEY&lt;/P&gt;&lt;P&gt;10/29/2020|GREEN HOUSE LIVING|2311 SHIRLEY COVE&lt;/P&gt;&lt;P&gt;11/21/2020|MISSION AT THE VILLA|1445 UINTA&lt;/P&gt;&lt;P&gt;11/2/2020|MISSION AT THE VILLA|1445 UINTA DRIVE&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 00:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701406#M214786</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2020-11-25T00:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Retain a value from previous obsevation by comparing first 10 characters of address field...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701418#M214797</link>
      <description>&lt;P&gt;And for your sample data set, what do you expect the desired results to look like?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 01:53:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701418#M214797</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-11-25T01:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Retain a value from previous obsevation by comparing first 10 characters of address field...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701429#M214802</link>
      <description>&lt;P&gt;Flag the previous record (old sub_date) as duplicate to delete it later.&lt;/P&gt;&lt;P&gt;Then my final data will be clean with one record per unit_name/addr1&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 03:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701429#M214802</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2020-11-25T03:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Retain a value from previous obsevation by comparing first 10 characters of address field...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701440#M214806</link>
      <description>&lt;P&gt;You could use a spelling distance function such as COMPLEV:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data to_clean;
infile cards dlm='|' truncover ;
input subDate :mmddyy10. unitName :$100. ADDR1 :$100. ;
format subDate yymmdd10.;
cards;
11/21/2020|BAIRD HUDSON ENTERPRISES|106 E MAIN
10/30/2020|BAIRD HUDSON ENTERPRISES|106 E MAIN STREET
10/30/2020|BIG HORN ENTERPRISE|146 S. BENT STREET
10/30/2020|BIG HORN ENTERPRISE|641 WARREN STREET
11/5/2020|BROOKDALE |
10/29/2020|BROOKDALE|2401 COUGAR AVENUE
10/30/2020|ELMCROFT|1551 SUGARLAND DRIVE
11/2/2020|ELMCROFT|1551 SUGARLAND DRIVE DRIVE
11/21/2020|GREEN HOUSE LIVING|2311 SHIRLEY
10/29/2020|GREEN HOUSE LIVING|2311 SHIRLEY COVE
11/21/2020|MISSION AT THE VILLA|1445 UINTA
11/2/2020|MISSION AT THE VILLA|1445 UINTA DRIVE
;

proc sort data=to_clean; by unitName subDate; run;

data to_clean_2;
set to_clean;
by unitName;
length goodAddr $100;
retain goodAddr;
if first.unitName then goodAddr = addr1;
else if complev(trim(goodAddr), trim(addr1), "IL:") &amp;gt; 2 then goodAddr = addr1;
run;

proc sort data=to_clean_2; by unitName goodAddr subDate; run;

data want;
set to_clean_2;
by unitName goodAddr;
if last.goodAddr;
run;

proc print noobs data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1606281354131.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51979i0FD554E862E900DC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1606281354131.png" alt="PGStats_0-1606281354131.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 05:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701440#M214806</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-11-25T05:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: Retain a value from previous obsevation by comparing first 10 characters of address field...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701616#M214863</link>
      <description>&lt;P&gt;Thank you so much.&amp;nbsp;First time hearing about &lt;SPAN class="token function keyword"&gt;complev&lt;/SPAN&gt;&amp;nbsp;function.&amp;nbsp;Very helpful and the code works perfectly as desired.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 17:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-a-value-from-previous-obsevation-by-comparing-first-10/m-p/701616#M214863</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2020-11-25T17:34:00Z</dc:date>
    </item>
  </channel>
</rss>

