BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
altijani
Quartz | Level 8

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!

1 ACCEPTED SOLUTION

Accepted Solutions
jebjur
SAS Employee

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/  

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Reeza
Super User
LAG doesn't work in SQL/Query Builder, it will work within a data step/SAS program. Alternatively, if you have SAS/ETS there may be timeseries procedures that allow you to create lagged variables via the GUI.
jebjur
SAS Employee

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/  

TomKari
Onyx | Level 15

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3340 views
  • 3 likes
  • 5 in conversation