<?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: lag calculate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712189#M219509</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Number;
datalines;
A 1  
A 2  
A 5  
A 19 
A 19 
B 1  
B 3  
;

data want;
   set have;
   by ID;
   if dif(Number) not in (0, 1) then numberoftimes + 1;
   if first.ID then numberoftimes = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID  Number  numberoftimes 
A   1       0 
A   2       0 
A   5       1 
A   19      2 
A   19      2 
B   1       0 
B   3       1 &lt;/PRE&gt;</description>
    <pubDate>Mon, 18 Jan 2021 18:57:16 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-01-18T18:57:16Z</dc:date>
    <item>
      <title>Test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712176#M219501</link>
      <description />
      <pubDate>Mon, 18 Jan 2021 19:19:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712176#M219501</guid>
      <dc:creator>Emma8</dc:creator>
      <dc:date>2021-01-18T19:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: lag calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712181#M219503</link>
      <description>&lt;P&gt;Please explain the value "1_0" in the second observation in more detail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2021 18:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712181#M219503</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-01-18T18:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: lag calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712183#M219504</link>
      <description />
      <pubDate>Mon, 18 Jan 2021 19:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712183#M219504</guid>
      <dc:creator>Emma8</dc:creator>
      <dc:date>2021-01-18T19:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: lag calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712184#M219505</link>
      <description>&lt;P&gt;OK, and what is the zero?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2021 18:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712184#M219505</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-01-18T18:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: lag calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712185#M219506</link>
      <description>I still don’t follow. Please explain further.</description>
      <pubDate>Mon, 18 Jan 2021 18:49:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712185#M219506</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-18T18:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: lag calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712189#M219509</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Number;
datalines;
A 1  
A 2  
A 5  
A 19 
A 19 
B 1  
B 3  
;

data want;
   set have;
   by ID;
   if dif(Number) not in (0, 1) then numberoftimes + 1;
   if first.ID then numberoftimes = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID  Number  numberoftimes 
A   1       0 
A   2       0 
A   5       1 
A   19      2 
A   19      2 
B   1       0 
B   3       1 &lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Jan 2021 18:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/712189#M219509</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-18T18:57:16Z</dc:date>
    </item>
  </channel>
</rss>

