DATA Step, Macro, Functions and more

how to get 3 variables (week no, week start date ,week end date ) from date varaible

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 76
Accepted Solution

how to get 3 variables (week no, week start date ,week end date ) from date varaible

Hi All,

I have a date variable from that I need to make 3 variables. like below. 

Date
26/03/2017
27/03/2017
28/03/2017
29/03/2017
30/03/2017
31/03/2017
01/04/2017
02/04/2017
03/04/2017
04/04/2017
05/04/2017
06/04/2017
07/04/2017
08/04/2017
09/04/2017
10/04/2017
11/04/2017
12/04/2017
13/04/2017
14/04/2017

15/04/2017

 

 

WeekWeek StartWeek End
126/03/201701/04/2017
202/04/201708/04/2017

 

Thanks,

SS.


Accepted Solutions
Solution
‎04-06-2018 06:37 AM
Super User
Posts: 9,919

Re: how to get 3 variables (week no, week start date ,week end date ) from date varaible

Use the intnx function:

data test;
curr_date = input('26/03/2017',ddmmyy10.);
week_start = intnx('week',curr_date,0,'b');
week_end = intnx('week',curr_date,0,'e');
format curr_date week_start week_end ddmmyy10.;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
‎04-06-2018 06:37 AM
Super User
Posts: 9,919

Re: how to get 3 variables (week no, week start date ,week end date ) from date varaible

Use the intnx function:

data test;
curr_date = input('26/03/2017',ddmmyy10.);
week_start = intnx('week',curr_date,0,'b');
week_end = intnx('week',curr_date,0,'e');
format curr_date week_start week_end ddmmyy10.;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

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

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