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

Hi,

 

 

 

I have only beginning inventory for day 4.03.2017 and no ending inventory. I am able to calculate ending inventory for this daybased on the beginning invory for this day and other variables that I have. But here where the problem ibegions....I need  SAS to use calculated ending inventory value from the day 4.03.2017 and have this equal to beginning inventory for dat 4.04.2017 and so on.

 

I am not sure where toe ven begin.

Thank you,

 

mag

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

In your data step

prev_ending=lag(ending_inventory);
if missing(beginning_inventory) then beginning_inventory=prev_ending;

 

Do yourself a huge favor and make any dates numeric and apply datetime formats to them, rather than having dates as character variables.

--
Paige Miller

View solution in original post

4 REPLIES 4
ballardw
Super User

It really helps to provide some example data and the desired result from that sample data.

Also, are your dates actual SAS date values or character?

mag2017
Calcite | Level 5

Hi,

 

The formats:  plan-character, week-character, beginning_inventory, usage and orders are nuemrical. 

 

Example of data:

 

Plant        Week                  beginning_Inventory   usage    orders                     ending inventory (has to be calculated....)

h               01/14/2017        30                                 5            22

a               01/21/2017       .

b               01/29/2017       .

 

I need to calculate ending inventory:   ending_inventory=beginning_inventory-usage+orders.

So for the first week it is easy to get ending_inventory whihc is 30-5+22=47  now this ending inventory from the week 01/14/2017 needs to become my beginning inventory for the week 01/29/2017 an so on...

 

Any idea how to approach this problem?

 

Thank you so much.

 

 

PaigeMiller
Diamond | Level 26

In your data step

prev_ending=lag(ending_inventory);
if missing(beginning_inventory) then beginning_inventory=prev_ending;

 

Do yourself a huge favor and make any dates numeric and apply datetime formats to them, rather than having dates as character variables.

--
Paige Miller
mag2017
Calcite | Level 5
Thank you. It worked.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Discussion stats
  • 4 replies
  • 911 views
  • 1 like
  • 3 in conversation