I have a SAS project where part of the project needs to track the flow of inventory: begin of day + new inventory - used inventory = end inventory for the day. The ending inventory for one day is now the beginning inventory for the start of the next day. I am trying to have SAS EG calculate this table but I don't know what function to use or how to code to pull the end count from the prior day in to the beginning count of the next day. Any suggestions? Currently I have the new and the used inventory counts. So I simply want to have SAS calculate both the beginning and ending counts.
Any help will be greatly appreciated. Thanks!
It depends on your data structure but RETAIN and/or LAG are all you likely need.
LAG() is a function, RETAIN is a statement that holds the value.
Thanks Reeza for your quick reply. I will try those out.
The first entry value for BEGIN is 0 (no inventory) and the END value for that day is equal to Begin + Incoming - Worked. Then the BEGIN of the next day is equal to the END value of the previous day.
I have researched both LOG and RETAIN and am not sure how to use them with what I am trying to do. The data I currently have is:
DATE TEAM GROUP CATEGORY BEGIN INCOMING OUTGOING END
6/25/2013 A 1 AUTO 1 0
7/2/2013 A 1 AUTO 1 0
7/9/2013 A 1 AUTO 0 1
7/10/2013 A 1 AUTO 2 0
7/11/2013 A 1 AUTO 2 0
7/12/2013 A 1 AUTO 0 2
What I want SAS to do (as an ongoing process step for a bigger project) is:
DATE TEAM GROUP CATEGORY BEGIN INCOMING OUTGOING END
6/25/2013 A 1 AUTO 0 1 0 1
7/2/2013 A 1 AUTO 1 1 0 2
7/9/2013 A 1 AUTO 2 0 1 1
7/10/2013 A 1 AUTO 1 2 0 3
7/11/2013 A 1 AUTO 3 2 0 5
7/12/2013 A 1 AUTO 5 0 2 3
Where the first entry value for BEGIN is 0 (no inventory) and the END value for that day is equal to Begin + Incoming - Worked. Then the BEGIN of the next day is equal to the END value of the previous day.
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.