BookmarkSubscribeRSS Feed
SAS09
Calcite | Level 5
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
deleted_user
Not applicable
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
SAS09
Calcite | Level 5
Peter,

The INTNX() worked beautifully! Thank you for your suggestion .

AJ
SushilNayak
Obsidian | Level 7
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;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 12070 views
  • 3 likes
  • 4 in conversation