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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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