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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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