<?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 LAG over partition by in a PROC SQL? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/LAG-over-partition-by-in-a-PROC-SQL/m-p/740453#M231304</link>
    <description>&lt;P&gt;How can I use lag over partition by in proc sql?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL; 
CREATE TABLE WANT AS 
select t1.account_id
from (select h1.account_id,
             lag(ACCOUNT_STATUS) over (partition by account_id order by ACCOUNT_CHANGE_DATE) as prev_status
      from HAVE h1
     )  t1
where prev_status NOT = 'B1' and ACCOUNT_STATUS = 'B1' and
      account_change_date &amp;gt;= '1Dec2020'd and
      account_change_date &amp;lt; '1Jan2021'd;
	  QUIT;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thank you!&lt;/P&gt;</description>
    <pubDate>Tue, 11 May 2021 13:17:18 GMT</pubDate>
    <dc:creator>tazz_bh</dc:creator>
    <dc:date>2021-05-11T13:17:18Z</dc:date>
    <item>
      <title>LAG over partition by in a PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-over-partition-by-in-a-PROC-SQL/m-p/740453#M231304</link>
      <description>&lt;P&gt;How can I use lag over partition by in proc sql?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL; 
CREATE TABLE WANT AS 
select t1.account_id
from (select h1.account_id,
             lag(ACCOUNT_STATUS) over (partition by account_id order by ACCOUNT_CHANGE_DATE) as prev_status
      from HAVE h1
     )  t1
where prev_status NOT = 'B1' and ACCOUNT_STATUS = 'B1' and
      account_change_date &amp;gt;= '1Dec2020'd and
      account_change_date &amp;lt; '1Jan2021'd;
	  QUIT;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 13:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-over-partition-by-in-a-PROC-SQL/m-p/740453#M231304</guid>
      <dc:creator>tazz_bh</dc:creator>
      <dc:date>2021-05-11T13:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: LAG over partition by in a PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-over-partition-by-in-a-PROC-SQL/m-p/740468#M231310</link>
      <description>&lt;P&gt;WINDOW functions&amp;nbsp; are not supported in Proc SQL&amp;nbsp;yet&amp;nbsp; .&lt;/P&gt;
&lt;PRE&gt;lag(ACCOUNT_STATUS) over (partition by account_id order by ACCOUNT_CHANGE_DATE) as prev_status&lt;/PRE&gt;
&lt;P&gt;This functionality can be achieved using Data Step.&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 14:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-over-partition-by-in-a-PROC-SQL/m-p/740468#M231310</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2021-05-11T14:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: LAG over partition by in a PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-over-partition-by-in-a-PROC-SQL/m-p/740470#M231312</link>
      <description>The LAG() function will work in a data step. &lt;BR /&gt;</description>
      <pubDate>Tue, 11 May 2021 14:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-over-partition-by-in-a-PROC-SQL/m-p/740470#M231312</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-11T14:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: LAG over partition by in a PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-over-partition-by-in-a-PROC-SQL/m-p/740485#M231323</link>
      <description>&lt;P&gt;SAS Proc Sql also does not support "partition by" syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL in general is not a sequential processing approach to data. It is based more on set operations if you remember those from junior high math classes. So "lag", which relies on a specific sequence of records, is not implemented for SQL.&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 14:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-over-partition-by-in-a-PROC-SQL/m-p/740485#M231323</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-11T14:43:57Z</dc:date>
    </item>
  </channel>
</rss>

