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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.