<?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: comparing row using lag function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/comparing-row-using-lag-function/m-p/626078#M184604</link>
    <description>&lt;P&gt;thanks all&lt;/P&gt;</description>
    <pubDate>Thu, 20 Feb 2020 09:25:38 GMT</pubDate>
    <dc:creator>harrylui</dc:creator>
    <dc:date>2020-02-20T09:25:38Z</dc:date>
    <item>
      <title>comparing row using lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-row-using-lag-function/m-p/625779#M184494</link>
      <description>&lt;P&gt;good day all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I borrowed an idea from this forum user and encounter an issue and don't know how to fix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what i expect is all the data will be changed to&amp;nbsp;A DRIVING SCHOOL by the program when passed the test(in this case should be all pass)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;however it fails because i set the lag(name) at beginning but when the name is changed by program,the lag(name) do not refresh!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there any way to enhance this program when the name is changed by program , at the same time the&amp;nbsp;lag(name) will refresh itself?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data testing;&lt;BR /&gt;infile datalines dlm="\";&lt;BR /&gt;input Name :$80. Category :$40.;&lt;BR /&gt;datalines;&lt;BR /&gt;A DRIVING SCHOOL\service&lt;BR /&gt;A DRIVING\service&lt;BR /&gt;A DRIVINGA\service&lt;BR /&gt;A DRIVINGb\service&lt;BR /&gt;A DRIVINGc\service&lt;/P&gt;
&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data testing2;&lt;BR /&gt;set testing;&lt;BR /&gt;_Name = lag(Name);&lt;BR /&gt;_Category = lag(Category);&lt;BR /&gt;dif=compged(Name, _Name);&lt;BR /&gt;dif2=compged(Category, _Category);&lt;BR /&gt;if dif&amp;lt;=100 and dif2 &amp;lt;=100 then &lt;BR /&gt;do;&lt;BR /&gt;Name = _Name;&lt;BR /&gt;Category = _Category;&lt;BR /&gt;match = "ok";end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what i expect the final output is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Cateory&lt;/P&gt;
&lt;P&gt;A DRIVING SCHOOL service&lt;/P&gt;
&lt;P&gt;A DRIVING SCHOOL service&lt;/P&gt;
&lt;P&gt;A DRIVING SCHOOL service&lt;/P&gt;
&lt;P&gt;A DRIVING SCHOOL service&lt;/P&gt;
&lt;P&gt;A DRIVING SCHOOL service&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 04:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-row-using-lag-function/m-p/625779#M184494</guid>
      <dc:creator>harrylui</dc:creator>
      <dc:date>2020-02-19T04:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: comparing row using lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-row-using-lag-function/m-p/625787#M184497</link>
      <description>&lt;P&gt;Not sure if this will really help you with your real data but I believe it implements more or less what you had in mind.&lt;/P&gt;
&lt;P&gt;The LAG() function is not working for you because it just always picks the value from the previous source row. I made the assumption that you want to RETAIN the value in case there is a "match".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dlm="\";
  input Name :$80. Category :$40.;
  datalines;
A DRIVING SCHOOL\service
A DRIVING\service
A DRIVINGA\service
A DRIVINGb\service
A DRIVINGc\service
;

data want;
  set have;
  length want_name $80 want_category $40;
  retain want_name want_category;

  min_len=min(lengthn(name),lengthn(want_name));
  dif=compged(substrn(Name,1,min_len), substrn(want_name,1,min_len));
  dif2=compged(Category, want_category);

  if not (dif&amp;lt;=100 and dif2 &amp;lt;=100) then
    do;
      want_name = Name;
      want_category = Category;
    end;

run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 07:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-row-using-lag-function/m-p/625787#M184497</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-19T07:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: comparing row using lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-row-using-lag-function/m-p/625789#M184498</link>
      <description>&lt;P&gt;The function lag returns the value of a variable in the previous observation of the dataset you are processing, not the values that are written to the output-dataset. So i think that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; is on the right track: you don't need lag, but retain&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 07:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-row-using-lag-function/m-p/625789#M184498</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-02-19T07:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: comparing row using lag function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-row-using-lag-function/m-p/626078#M184604</link>
      <description>&lt;P&gt;thanks all&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 09:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-row-using-lag-function/m-p/626078#M184604</guid>
      <dc:creator>harrylui</dc:creator>
      <dc:date>2020-02-20T09:25:38Z</dc:date>
    </item>
  </channel>
</rss>

