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

Hi, 

 

I need to add the date incrementally from a certain starting date.  My data look like this

 

data try;
input Product factory Week quantity ;
datalines;A 1 1 3
A 1 1 4
A 1 1 5
A 1 1 6
A 1 1 3
A 1 1 5
A 1 1 5
A 1 2 6
A 1 2 5
A 1 2 5
A 1 2 4
A 1 2 5
A 1 2 4
A 1 2 5
B 1 1 3
B 1 1 2
B 1 1 3
B 1 1 2
B 1 1 3
B 1 1 2
B 1 1 3
B 1 2 5
B 1 2 4
B 1 2 5
B 1 2 5
B 1 2 4
B 1 2 5
B 1 2 5
; run;



 

The week column tells the the number of the week. Each week is repeated for 7 rows to give information for 7 days. I want to the add the date incrementally  from a certain starting date. So the days change based on the week sequence and the circle need to be done for each product . 

 

The table I want should look like this 

product   factory       Week      Quantity      Date 

A       1        1       3        20200120
A       1        1       5        20200121
A       1        1       6        20200122

.

,

,
B       1        1       3        20200120
B       1        1       2        20200121
B       1        1       3        20200121

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

If I understand right then below should do (for a week starting on Monday).

data have;
  input Product $ factory Week quantity;
  datalines;
A 1 1 3
A 1 1 4
A 1 1 5
A 1 1 6
A 1 1 3
A 1 1 5
A 1 1 5
A 1 2 6
A 1 2 5
A 1 2 5
A 1 2 4
A 1 2 5
A 1 2 4
A 1 2 5
B 1 1 3
B 1 1 2
B 1 1 3
B 1 1 2
B 1 1 3
B 1 1 2
B 1 1 3
B 1 2 5
B 1 2 4
B 1 2 5
B 1 2 5
B 1 2 4
B 1 2 5
B 1 2 5
;

%let start_dt='20jan2020'd;
data want;
  set have;
  by product factory week;
  format date yymmddn.;
  if first.week then
    date=intnx('week.2',&start_dt,week-1,'b');
  else date+1;
run;

proc print;
run;  

 

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

If I understand right then below should do (for a week starting on Monday).

data have;
  input Product $ factory Week quantity;
  datalines;
A 1 1 3
A 1 1 4
A 1 1 5
A 1 1 6
A 1 1 3
A 1 1 5
A 1 1 5
A 1 2 6
A 1 2 5
A 1 2 5
A 1 2 4
A 1 2 5
A 1 2 4
A 1 2 5
B 1 1 3
B 1 1 2
B 1 1 3
B 1 1 2
B 1 1 3
B 1 1 2
B 1 1 3
B 1 2 5
B 1 2 4
B 1 2 5
B 1 2 5
B 1 2 4
B 1 2 5
B 1 2 5
;

%let start_dt='20jan2020'd;
data want;
  set have;
  by product factory week;
  format date yymmddn.;
  if first.week then
    date=intnx('week.2',&start_dt,week-1,'b');
  else date+1;
run;

proc print;
run;  

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 427 views
  • 0 likes
  • 2 in conversation