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.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Discussion stats
  • 4 replies
  • 661 views
  • 1 like
  • 3 in conversation