<?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: Count changes in column (lag function) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column-lag-function/m-p/748321#M235039</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/315439"&gt;@PatrykSAS&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/315439"&gt;@PatrykSAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I heard about lag function which could be helpful but I am not sure how to use it&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Here's how the LAG function could be used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
count = value~=lag(value) &amp;amp; id=lag(id);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 16 Jun 2021 12:24:38 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-06-16T12:24:38Z</dc:date>
    <item>
      <title>Count changes in column (lag function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column-lag-function/m-p/748319#M235037</link>
      <description>&lt;P&gt;I would like to count value changes in a column like below:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;ID&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;VALUE&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;COUNT&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;10&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;10&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;12&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;15&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;In this example ID and VALUE is my data and I want to make count column equal 1 each time the value change in given ID&lt;/P&gt;
&lt;P&gt;I heard about lag function which could be helpful but I am not sure how to use it&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jun 2021 12:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column-lag-function/m-p/748319#M235037</guid>
      <dc:creator>PatrykSAS</dc:creator>
      <dc:date>2021-06-16T12:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: Count changes in column (lag function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column-lag-function/m-p/748320#M235038</link>
      <description>&lt;PRE&gt;data have;
input ID	VALUE;
cards;
1	10	
1	10	
1	12	
1	15
;
data want;
 set have;
 by id value notsorted;
 count=first.value;
 if first.id then count=0;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jun 2021 12:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column-lag-function/m-p/748320#M235038</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-16T12:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count changes in column (lag function)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column-lag-function/m-p/748321#M235039</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/315439"&gt;@PatrykSAS&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/315439"&gt;@PatrykSAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I heard about lag function which could be helpful but I am not sure how to use it&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Here's how the LAG function could be used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
count = value~=lag(value) &amp;amp; id=lag(id);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jun 2021 12:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-changes-in-column-lag-function/m-p/748321#M235039</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-06-16T12:24:38Z</dc:date>
    </item>
  </channel>
</rss>

