<?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: Mimicking SQL window functions with the DATA step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Mimicking-SQL-window-functions-with-the-DATA-step/m-p/483096#M125238</link>
    <description>&lt;P&gt;It is much easier using a data step since SAS will process the records in order.&lt;/P&gt;
&lt;P&gt;Do you want to consider the first value for each ID to be PASSED or not?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  by id val ;
  passed = dif(val)=1 ;
  if first.id then passed=1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 01 Aug 2018 16:16:14 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-08-01T16:16:14Z</dc:date>
    <item>
      <title>Mimicking SQL window functions with the DATA step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mimicking-SQL-window-functions-with-the-DATA-step/m-p/483093#M125237</link>
      <description>&lt;P&gt;I need to test that a column is monotonic within a group.&amp;nbsp; In other words that for a given group each subsequent row has an ascending number.&amp;nbsp; So if id = 100 and there are three rows it will have 1, 2, 3.&amp;nbsp; With PostgreSQL I would use a window function.&amp;nbsp; Something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;CREATE TEMPORARY TABLE foo (
	id integer,
	val integer 
);

INSERT INTO foo VALUES (1, 1), (1, 2), (1, 3), (2, 1), (3, 1), (3, 2);

SELECT
	id,
	CASE
		WHEN LAG(val) OVER (PARTITION BY id) = val - 1 THEN TRUE
		WHEN LAG(val) OVER (PARTITION BY id) IS NULL THEN TRUE
		ELSE FALSE
	END AS passed
FROM foo;&lt;/PRE&gt;&lt;P&gt;Is there any equivalent function in SAS?&amp;nbsp; The SAS lag function does not work with group partitions like in SQL.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Aug 2018 16:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mimicking-SQL-window-functions-with-the-DATA-step/m-p/483093#M125237</guid>
      <dc:creator>tomcmacdonald</dc:creator>
      <dc:date>2018-08-01T16:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Mimicking SQL window functions with the DATA step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mimicking-SQL-window-functions-with-the-DATA-step/m-p/483096#M125238</link>
      <description>&lt;P&gt;It is much easier using a data step since SAS will process the records in order.&lt;/P&gt;
&lt;P&gt;Do you want to consider the first value for each ID to be PASSED or not?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  by id val ;
  passed = dif(val)=1 ;
  if first.id then passed=1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Aug 2018 16:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mimicking-SQL-window-functions-with-the-DATA-step/m-p/483096#M125238</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-01T16:16:14Z</dc:date>
    </item>
  </channel>
</rss>

