<?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: read and compare next observation in sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743208#M232627</link>
    <description>Thanks. yes I tried with lag function only.  just wanted to check is there any other way to compare values in variable?&lt;BR /&gt;Can we run a loop , array ? please suggest</description>
    <pubDate>Sun, 23 May 2021 11:38:23 GMT</pubDate>
    <dc:creator>Aexor</dc:creator>
    <dc:date>2021-05-23T11:38:23Z</dc:date>
    <item>
      <title>read and compare next observation in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743196#M232617</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have this table:&lt;/P&gt;
&lt;P&gt;id&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;I want to set a flag if any value change is there from the previous one.&lt;/P&gt;
&lt;P&gt;as shown below:&lt;/P&gt;
&lt;P&gt;id flag&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp;N&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; N&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; N&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; Y&lt;/P&gt;
&lt;P&gt;0&amp;nbsp; Y&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; Y&lt;/P&gt;
&lt;P&gt;here i tried using lag function and compare the value to get flag. Please suggest any other ways to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 23 May 2021 07:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743196#M232617</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-05-23T07:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: read and compare next observation in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743197#M232618</link>
      <description>&lt;P&gt;The LAG function is the proper tool for this, use it (Maxim 14).&lt;/P&gt;</description>
      <pubDate>Sun, 23 May 2021 07:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743197#M232618</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-23T07:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: read and compare next observation in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743203#M232622</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id;
datalines;
1
0
0
0
1
0
1
;

data want;
   set have;
   flag = ifc(id = lag(id) | _N_ = 1, "N", "Y");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 May 2021 09:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743203#M232622</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-05-23T09:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: read and compare next observation in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743208#M232627</link>
      <description>Thanks. yes I tried with lag function only.  just wanted to check is there any other way to compare values in variable?&lt;BR /&gt;Can we run a loop , array ? please suggest</description>
      <pubDate>Sun, 23 May 2021 11:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743208#M232627</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-05-23T11:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: read and compare next observation in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743209#M232628</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327170"&gt;@Aexor&lt;/a&gt;&amp;nbsp;alternate solution with the help of proc sql;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id;
datalines;
5
0
0
0
1
0
1
;

proc sql noprint;
create table have1 as
select *,monotonic() as c from have;
create table WANT as
select a.id,ifc(a.id eq b.id | a.c=1,'N','Y') as flag from have1 as a left join have1 as b on a.c=b.c+1;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 May 2021 11:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-and-compare-next-observation-in-sas/m-p/743209#M232628</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2021-05-23T11:42:59Z</dc:date>
    </item>
  </channel>
</rss>

