<?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 the information in a row with the next row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-the-information-in-a-row-with-the-next-row/m-p/325140#M72283</link>
    <description>&lt;P&gt;Unless I'm missing something, you're asking for something that SAS can do relatively easily:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id value notsorted;&lt;/P&gt;
&lt;P&gt;if first.value=0 or last.value=0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the IDs you are looking for, it outputs multiple observations (not just one).&lt;/P&gt;</description>
    <pubDate>Mon, 16 Jan 2017 22:21:50 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-01-16T22:21:50Z</dc:date>
    <item>
      <title>Comparing the information in a row with the next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-the-information-in-a-row-with-the-next-row/m-p/325054#M72245</link>
      <description>&lt;P&gt;Hi everyone, I have a dataset with over 15 million entries. I'm looking to compare the row below with the one above to look for all unique ID's that have a different value next to them. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AB1234567, 145633431&lt;BR /&gt;AB1234567, 145633431&lt;BR /&gt;AB1234568, 145633431&lt;BR /&gt;AB1234568, 145633432&lt;BR /&gt;AB1234566, 145631513&lt;BR /&gt;AB1234565, 145635315&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case, I am creating a counter or loop to look for all unique ID's that appear twice, but have a different value. In this case the only one is AB1234568. I want to ignore AB1234567 because it&amp;nbsp;has the same value next to it both times.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using a counter already and was able to find all values that came up twice but it was very inefficient and did not solve my problem:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt; &lt;STRONG&gt;summary&lt;/STRONG&gt; DATA=AUTO NWAY MISSING;&lt;/P&gt;&lt;P&gt;&amp;nbsp; class&amp;nbsp; NIV nopol;&lt;/P&gt;&lt;P&gt;&amp;nbsp; VAR&amp;nbsp;&amp;nbsp; xyz;&lt;/P&gt;&lt;P&gt;&amp;nbsp; OUTPUT OUT=DOUBLES(DROP=_TYPE_ _FREQ_) sum= ;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sort&lt;/STRONG&gt; data=DOUBLES;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by NIV NOPOL;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; AUTO2;&lt;/P&gt;&lt;P&gt;SET DOUBLES;&lt;/P&gt;&lt;P&gt;IF XYZ=&lt;STRONG&gt;2&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have not used loops in SAS before but I am setting them up by using other people's code as an example. If anyone can help it's appreciated. Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 16:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-the-information-in-a-row-with-the-next-row/m-p/325054#M72245</guid>
      <dc:creator>amanmurba</dc:creator>
      <dc:date>2017-01-16T16:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing the information in a row with the next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-the-information-in-a-row-with-the-next-row/m-p/325055#M72246</link>
      <description>&lt;P&gt;You can use either lag or retain functions too look at previous values:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if lag(id)=id and lag(value) ne value then new_flag=1;
run;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Jan 2017 16:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-the-information-in-a-row-with-the-next-row/m-p/325055#M72246</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-16T16:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing the information in a row with the next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-the-information-in-a-row-with-the-next-row/m-p/325065#M72249</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming your data is grouped by ID but not sorted by group or by VALUE, here's one way using the lag function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (rename=(_ID=ID));
        set have end=_EOF;
        drop ID VALUE _VALUE;
        _ID=lag1(ID);
        _VALUE=lag1(VALUE);
        if _ID eq ID and _VALUE ne VALUE then COUNT+1;
        if _EOF or _ID ne ID then do;
           if COUNT gt 1 then output;
           COUNT=1;
        end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will output the ID and the count of distinct values for VALUE if &amp;gt; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More on LAG function here:&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212547.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212547.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 16:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-the-information-in-a-row-with-the-next-row/m-p/325065#M72249</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-01-16T16:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing the information in a row with the next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-the-information-in-a-row-with-the-next-row/m-p/325140#M72283</link>
      <description>&lt;P&gt;Unless I'm missing something, you're asking for something that SAS can do relatively easily:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id value notsorted;&lt;/P&gt;
&lt;P&gt;if first.value=0 or last.value=0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the IDs you are looking for, it outputs multiple observations (not just one).&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2017 22:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-the-information-in-a-row-with-the-next-row/m-p/325140#M72283</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-16T22:21:50Z</dc:date>
    </item>
  </channel>
</rss>

