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

I've attached a file with some code.  I would like to get the equivalent to =B3+C3-D2-G2 in excel but my code is not performing the way that I want it too.  I'm not sure if lag what I should be using here.  Any help is appreciated.

Thank You,

Mark

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

LAG has some pretty complex relationships with conditional execution.

You would be better to create a new variable such as Lpayment= lag(payment); BEFORE the IF not line of code and use Lpayment instead of lag(payment) within the calculation.

View solution in original post

3 REPLIES 3
ballardw
Super User

LAG has some pretty complex relationships with conditional execution.

You would be better to create a new variable such as Lpayment= lag(payment); BEFORE the IF not line of code and use Lpayment instead of lag(payment) within the calculation.

jakarman
Barite | Level 11

do not confuse the queue function with the lag function.

There is no complexity when you understand that what SAS has implemented is a QUEUE http://en.wikipedia.org/wiki/Queue_(abstract_data_type)  and has named that wrong as LAG http://msdn.microsoft.com/en-us/library/hh231256.aspx

Wrong naming can cause confusions, correct that and it will become easy. 

---->-- ja karman --<-----
Steelers_In_DC
Barite | Level 11

Before the IF NOT line payment has no value, I'm putting it after the if not and after the payment = statement.  That seems to get me the output I am looking for.

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 970 views
  • 0 likes
  • 3 in conversation