BookmarkSubscribeRSS Feed
gregor1
Quartz | Level 8

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!

4 REPLIES 4
Reeza
Super User

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.

gregor1
Quartz | Level 8

Thanks Reeza for your quick reply.  I will try those out.

gregor1
Quartz | Level 8

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.

 

gregor1
Quartz | Level 8

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.

 

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
  • 1518 views
  • 0 likes
  • 2 in conversation