Hi Community,
What is the function equivalent to Lag in enterprise guide? In other words, how can I create a new variable equals 1 if Var = Var from the previous observation?
Thanks!
The Enterprise Guide query builder uses PROC SQL under the covers, and the LAG function is not valid in PROC SQL. You would either need to use DATA step code in a program node, or there is a custom task you can use that will calculate the lag.
http://support.sas.com/documentation/onlinedoc/guide/customtasks/index.htm
Under the quick links for Eguide 4.3 and later, choose the link for the Example: Calculate Lag. Download the zip file to your PC, and save the CalculateLag.dll file to 'C:\Program Files\SASHome\SASEnterpriseGuide\7.1\Custom'.
When you open a new session of Eguide, under Tools - Add-in Manager, you should see the Compute Lag/Dif custom task.
You may need to unblock the DLL file on your PC as well, here is more information:
http://blogs.sas.com/content/sasdummy/2013/05/19/unblocking-custom-task-dlls/
Lag function is a Base SAS function and is available for any version of SAS 9.2 upwards at least. So either your EG is very old, in which case upgrade, or something else is wrong.
The Enterprise Guide query builder uses PROC SQL under the covers, and the LAG function is not valid in PROC SQL. You would either need to use DATA step code in a program node, or there is a custom task you can use that will calculate the lag.
http://support.sas.com/documentation/onlinedoc/guide/customtasks/index.htm
Under the quick links for Eguide 4.3 and later, choose the link for the Example: Calculate Lag. Download the zip file to your PC, and save the CalculateLag.dll file to 'C:\Program Files\SASHome\SASEnterpriseGuide\7.1\Custom'.
When you open a new session of Eguide, under Tools - Add-in Manager, you should see the Compute Lag/Dif custom task.
You may need to unblock the DLL file on your PC as well, here is more information:
http://blogs.sas.com/content/sasdummy/2013/05/19/unblocking-custom-task-dlls/
Just to expand a little on @jebjur's comment, it may seem weird that LAG doesn't work in PROC SQL.
It's important to know that SQL was originally intended as a "set" language, where the concept of processing one record after another doesn't exist. That's why the DATA step is so necessary for problems such as this. It's not a defect in SAS.
Tom
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.