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

Hello,

 

I've below input , Where i need to change the dates with  Week number , Starting 03JUN2019-09JUN2019 would be WEEK1 , 10JUN2019-16JUN2019 would be Shown as WEEK2 and so on.......

 

WeekStart  WeekEnd
03Jun2019 09Jun2019
10Jun2019 16Jun2019
17Jun2019 23Jun2019
24Jun2019 30Jun2019
01Jul2019 07Jul2019
08Jul2019 14Jul2019
15Jul2019 21Jul2019
22Jul2019 28Jul2019
29Jul2019 04Aug2019
05Aug2019 11Aug2019
12Aug2019 18Aug2019
19Aug2019 25Aug2019
26Aug2019 01Sep2019
02Sep2019 08Sep2019
09Sep2019 15Sep2019
16Sep2019 22Sep2019
23Sep2019 29Sep2019
30Sep2019 06Oct2019
07Oct2019 13Oct2019
14Oct2019 20Oct2019
21Oct2019 27Oct2019
28Oct2019 03Nov2019
04Nov2019 10Nov2019
11Nov2019 17Nov2019
18Nov2019 24Nov2019
25Nov2019 01Dec2019
02Dec2019 08Dec2019
09Dec2019 15Dec2019

 

I think creating the PROC FORMAT would be more compatible way, Looking for help to get proc format created.

 

Let me know if you have any other approach to tackle this.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You don't really need a format.  You can could just use INTCK() function call. Use WEEK.2 interval since June 3rd is a Monday instead of a Sunday.

data test;
  input date date9.;
  week = 1+intck('week.2','03JUN2019'd,date);
  format date date9.;
cards;
11JUN2019
24JUN2019
30JUN2019
01JUL2019
;
Obs         date    week

 1     11JUN2019      2
 2     24JUN2019      4
 3     30JUN2019      4
 4     01JUL2019      5

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16
proc sort data=have;
by weekstart weekend;
run;

data want;
set have;
by weekstart weekend;
week=cats('WEEK',put(_n_,best.));
run;

Thanks,
Jag
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
 
Tom
Super User Tom
Super User

You don't really need a format.  You can could just use INTCK() function call. Use WEEK.2 interval since June 3rd is a Monday instead of a Sunday.

data test;
  input date date9.;
  week = 1+intck('week.2','03JUN2019'd,date);
  format date date9.;
cards;
11JUN2019
24JUN2019
30JUN2019
01JUL2019
;
Obs         date    week

 1     11JUN2019      2
 2     24JUN2019      4
 3     30JUN2019      4
 4     01JUL2019      5
ballardw
Super User

@jaiganesh wrote:

Hello,

 

I've below input , Where i need to change the dates with  Week number , Starting 03JUN2019-09JUN2019 would be WEEK1 , 10JUN2019-16JUN2019 would be Shown as WEEK2 and so on.......

 

WeekStart  WeekEnd
03Jun2019 09Jun2019
10Jun2019 16Jun2019
17Jun2019 23Jun2019
24Jun2019 30Jun2019
01Jul2019 07Jul2019
08Jul2019 14Jul2019
15Jul2019 21Jul2019
22Jul2019 28Jul2019
29Jul2019 04Aug2019
05Aug2019 11Aug2019
12Aug2019 18Aug2019
19Aug2019 25Aug2019
26Aug2019 01Sep2019
02Sep2019 08Sep2019
09Sep2019 15Sep2019
16Sep2019 22Sep2019
23Sep2019 29Sep2019
30Sep2019 06Oct2019
07Oct2019 13Oct2019
14Oct2019 20Oct2019
21Oct2019 27Oct2019
28Oct2019 03Nov2019
04Nov2019 10Nov2019
11Nov2019 17Nov2019
18Nov2019 24Nov2019
25Nov2019 01Dec2019
02Dec2019 08Dec2019
09Dec2019 15Dec2019

 

I think creating the PROC FORMAT would be more compatible way, Looking for help to get proc format created.

 

Let me know if you have any other approach to tackle this.

 

 

 


If your data crosses a year boundary you need to indicate what you expect for some of the values into the next calendar year. Weeks are not a very nice interval to play with because they do not divide a years or months into integer intervals.

 

 

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!
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
  • 4 replies
  • 619 views
  • 3 likes
  • 5 in conversation