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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.