Hi All,
I need to finds the first Monday after 5th of every month.
Please help
I used the following code to find the 5th of every month
data a;
format rundate date9.;
rundate=(intnx('Month',today(),+1))+4;
run;
You are using the correct function, but the parameters are wrong.
data bob;
fifth = '05Jun2018'd;
target = intnx('WEEK', fifth, 1, 'B') + 1;
format fifth target ddmmyyp10.;
run;
What do you expect if the 5th is a Monday?
Use a formula that is based on weekday(), and create a modulated offset:
data test;
input mydate yymmdd10.;
fifth = intnx('month',mydate,0,'b') + 4;
mon_after_fifth = fifth + mod(9 - weekday(fifth),7);
format mydate fifth mon_after_fifth yymmddd10.;
wd = weekday(mon_after_fifth); /* just to be sure we always get a monday */
cards;
2018-06-02
2018-05-10
2018-03-02
;
run;
I put the March date in because 2018-03-05 was a Monday.
If 03-05-2018 is a Monday, shouldn't the program return 03-12-2018 instead of 03-05-2018?
@Astounding wrote:
If 03-05-2018 is a Monday, shouldn't the program return 03-12-2018 instead of 03-05-2018?
That would need a little tweaking, but only the OP can give us the definite answer.
Can't think of anything much prettier than below to return for any given current_date a run_date of the next Monday of the month on the 5th or after AND this run_date also always being >= current_date.
data sample;
format currdate rundate _mon5orAfter weekdate17.;
do currdate='01jan2018'd to today();
_mon5orAfter=intnx('week.3',intnx('month',currdate,0,'b')+4,0,'e');
rundate=ifn(currdate>_mon5orAfter,intnx('week.3',intnx('month',currdate,1,'b')+4,0,'e'),_mon5orAfter);
output;
end;
stop;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.