Community talk about communities.sas.com. Meta!

copy value from periouvs week to the next week

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

copy value from periouvs week to the next week

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


Accepted Solutions
Solution
‎04-13-2017 04:16 PM
Trusted Advisor
Posts: 1,631

Re: copy value from periouvs week to the next week

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.

View solution in original post


All Replies
Super User
Posts: 10,538

Re: copy value from periouvs week to the next week

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?

New Contributor
Posts: 3

Re: copy value from periouvs week to the next week

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.

 

 

Solution
‎04-13-2017 04:16 PM
Trusted Advisor
Posts: 1,631

Re: copy value from periouvs week to the next week

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.

New Contributor
Posts: 3

Re: copy value from periouvs week to the next week

Thank you. It worked.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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