SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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