Desktop productivity for business analysts and programmers

Prior day's data as beginning value of current day

Reply
Contributor
Posts: 35

Prior day's data as beginning value of current day

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!

Super User
Posts: 23,959

Re: Prior day's data as beginning value of current day

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.

Contributor
Posts: 35

Re: Prior day's data as beginning value of current day

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

Contributor
Posts: 35

Re: Prior day's data as beginning value of current day

[ Edited ]

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.

 

Contributor
Posts: 35

Re: Prior day's data as beginning value of current 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.

 

Ask a Question
Discussion stats
  • 4 replies
  • 186 views
  • 0 likes
  • 2 in conversation