Hi,
I would like to increment the week number by 1 every 7 days, starting from Apr 4 to "some end date".
My dataset looks like this:
Date | pcode |
4-Apr-14 | V5C0B3 |
4-Apr-14 | V5C0B4 |
5-Apr-14 | V5C0B3 |
5-Apr-14 | V5C0B4 |
6-Apr-14 | V5C0B3 |
6-Apr-14 | V5C0B4 |
7-Apr-14 | V5C0B3 |
7-Apr-14 | V5C0B4 |
8-Apr-14 | V5C0B3 |
8-Apr-14 | V5C0B4 |
9-Apr-14 | V5C0B3 |
9-Apr-14 | V5C0B4 |
10-Apr-14 | V5C0B3 |
10-Apr-14 | V5C0B4 |
11-Apr-14 | V5C0B3 |
11-Apr-14 | V5C0B4 |
12-Apr-14 | V5C0B3 |
12-Apr-14 | V5C0B4 |
13-Apr-14 | V5C0B3 |
13-Apr-14 | V5C0B4 |
14-Apr-14 | V5C0B3 |
14-Apr-14 | V5C0B4 |
15-Apr-14 | V5C0B3 |
15-Apr-14 | V5C0B4 |
16-Apr-14 | V5C0B3 |
16-Apr-14 | V5C0B4 |
17-Apr-14 | V5C0B3 |
17-Apr-14 | V5C0B4 |
18-Apr-14 | V5C0B3 |
18-Apr-14 | V5C0B4 |
19-Apr-14 | V5C0B3 |
19-Apr-14 | V5C0B4 |
and I want it to look like this:
Date | pcode | WEEK |
4-Apr-14 | V5C0B3 | 1 |
4-Apr-14 | V5C0B4 | 1 |
5-Apr-14 | V5C0B3 | 1 |
5-Apr-14 | V5C0B4 | 1 |
6-Apr-14 | V5C0B3 | 1 |
6-Apr-14 | V5C0B4 | 1 |
7-Apr-14 | V5C0B3 | 1 |
7-Apr-14 | V5C0B4 | 1 |
8-Apr-14 | V5C0B3 | 1 |
8-Apr-14 | V5C0B4 | 1 |
9-Apr-14 | V5C0B3 | 1 |
9-Apr-14 | V5C0B4 | 1 |
10-Apr-14 | V5C0B3 | 1 |
10-Apr-14 | V5C0B4 | 1 |
11-Apr-14 | V5C0B3 | 2 |
11-Apr-14 | V5C0B4 | 2 |
12-Apr-14 | V5C0B3 | 2 |
12-Apr-14 | V5C0B4 | 2 |
13-Apr-14 | V5C0B3 | 2 |
13-Apr-14 | V5C0B4 | 2 |
14-Apr-14 | V5C0B3 | 2 |
14-Apr-14 | V5C0B4 | 2 |
15-Apr-14 | V5C0B3 | 2 |
15-Apr-14 | V5C0B4 | 2 |
16-Apr-14 | V5C0B3 | 2 |
16-Apr-14 | V5C0B4 | 2 |
17-Apr-14 | V5C0B3 | 2 |
17-Apr-14 | V5C0B4 | 2 |
18-Apr-14 | V5C0B3 | 3 |
18-Apr-14 | V5C0B4 | 3 |
19-Apr-14 | V5C0B3 | 3 |
19-Apr-14 | V5C0B4 | 3 |
Thanks in advance!
I have to assume you made a slight error in your post and that April 18 would increment to week=3. Here's a statement you could add to your DATA step:
week = 1 + int( (date - '04apr2014'd) / 7);
Good luck.
I have to assume you made a slight error in your post and that April 18 would increment to week=3. Here's a statement you could add to your DATA step:
week = 1 + int( (date - '04apr2014'd) / 7);
Good luck.
thanks!!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.