- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-06-2009 04:49 PM
(13357 views)
Wondering if someone could help me with the following problem. I have a dataset that contains a column called create date. Using this field I would like to identify the weekend date for any given create date. Any thoughts on how this could be done?
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
the function INTNX() will provide the next date that satisfies the interval boundary you seek. There are lots of examples at the web page http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000990883.htm .
Whether you want next weekend (Friday/Saturday/Sunday), or last, you'll find an interval definition to suit.
PeterC
Whether you want next weekend (Friday/Saturday/Sunday), or last, you'll find an interval definition to suit.
PeterC
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Peter,
The INTNX() worked beautifully! Thank you for your suggestion .
AJ
The INTNX() worked beautifully! Thank you for your suggestion .
AJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi SAS09,
A simple do loop with WEEKDAY function can also solve you problem.
data dx;
input cretdt YYMMDD10.;
do i = 0 to 7 until(weekdaynum in(1,7)) ;
weekdaynum=weekday(cretdt + i);
weekend_date=cretdt+i;
end;
format cretdt weekend_date YYMMDD10.;
datalines;
2009-04-03
2009-04-09
2009-04-15
;
run;
proc print;run;
A simple do loop with WEEKDAY function can also solve you problem.
data dx;
input cretdt YYMMDD10.;
do i = 0 to 7 until(weekdaynum in(1,7)) ;
weekdaynum=weekday(cretdt + i);
weekend_date=cretdt+i;
end;
format cretdt weekend_date YYMMDD10.;
datalines;
2009-04-03
2009-04-09
2009-04-15
;
run;
proc print;run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To Sushil: I recommend you consider reading up on the much simpler approach, using the INTNX function, where the desired result can be generated in one assignment statement, given any SAS date variable.
Scott Barry
SBBWorks, Inc.
Scott Barry
SBBWorks, Inc.