I have a dataset called myds which has the below columns date code I would like to add another column called prevmonthdate which is the last business date of the previous month Thanks, HD
Probably a better way than this, specifically to check if its a Saturday/Sunday. I also believe this question is answered on here, so searching will probably get you a better response.
data have;
do i=1 to 12;
date=mdy(i, 15, 2014);
output;
end;
run;
data want;
set have;
last_business_day=intnx('month', date, -1, 'end');
if weekday(last_business_day) =1 then last_business_day=last_business_day-2;
else if weekday(last_business_day)=7 then last_business_day=last_business_day-1;
format date last_business_day date9.;
run;
Do you need to account for holidays?
no just business days..thanks
So which are your business days?
sorry for being so unclear long day.. i mean just monday to friday only week days
Probably a better way than this, specifically to check if its a Saturday/Sunday. I also believe this question is answered on here, so searching will probably get you a better response.
data have;
do i=1 to 12;
date=mdy(i, 15, 2014);
output;
end;
run;
data want;
set have;
last_business_day=intnx('month', date, -1, 'end');
if weekday(last_business_day) =1 then last_business_day=last_business_day-2;
else if weekday(last_business_day)=7 then last_business_day=last_business_day-1;
format date last_business_day date9.;
run;
THank you. Both answers are correct!! Thanks very much
SASKiwi answer is preferable to mine, more efficient.
Alternative way:
Data want;
Date = "21Feb2014"d;
last_month_busday = intnx('WEEKDAY', intnx('MONTH', date, -1, 'END'), 0);
format last_month_busday date9.;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.