I need to test that a column is monotonic within a group. In other words that for a given group each subsequent row has an ascending number. So if id = 100 and there are three rows it will have 1, 2, 3. With PostgreSQL I would use a window function. Something like this: 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; Is there any equivalent function in SAS? The SAS lag function does not work with group partitions like in SQL.
... View more