I have created proc sql query in SAS program, but need to use LAG function and it tell me it can't be used in proc sql, just in data step. Code:
proc sql;
CREATE TABLE agg_table AS
SELECT USER, MAX(TIME) AS LAST_TIME, SUM(BONUS) AS BONUS_SUM, LAG(EXPDT) AS EXPDT_LAG FROM WORK.MY_DATA GROUP BY USER_ID;
So, I don't how to combine proc sql and datastep into one query to get one table as an output? Or maybe there is a better approach to the whole problem? Thanks
sumandlagin a single SQL query / data step unless you want to write down a rather complicated code retaining an array of lagged observations. If there is no row-number column inMY_DATAthat could be used to join theLAG(EXPDT), you can for example first calculateLAG(EXPDT)in data step and then calculate the aggregate columns in proc sql. - Petr