Page 1 of 1
checking if date is last weekday of the month
Posted: Mon Feb 01, 2021 12:59 pm
by amrsherif
Hi,
I am using a D5 workfile, and would like to know if there is a simple way for obtaining the last weekday of each month (as a string or date).
Thanks
Re: checking if date is last weekday of the month
Posted: Mon Feb 01, 2021 1:17 pm
by EViews Gareth
Code: Select all
smpl if @month<>@month(1)
alpha mydate = @datestr(@date, "YYYY-MM-DD")
svector lastdates =@uniquevals(mydate)
Re: checking if date is last weekday of the month
Posted: Mon Feb 01, 2021 2:16 pm
by amrsherif
Thanks for this. It works. Can you please briefly explain how the second line works? I thought @date returns the current date.
Also how can i change it to weekdays? Right now, it gives the 31st of Jan 2021.
Thanks again
Re: checking if date is last weekday of the month
Posted: Mon Feb 01, 2021 3:34 pm
by EViews Gareth
Second line just changes @date into the string representation of the date.
If your workfile is D5, there won't be any weekends in it, so it won't report them.
Re: checking if date is last weekday of the month
Posted: Mon Feb 01, 2021 3:42 pm
by EViews Gareth
I should, however, note that the smpl statement will miss the last month in your workfile, so you could modify it with:
Code: Select all
smpl if @month<>@month(1) or @trend=@max(@trend)
Re: checking if date is last weekday of the month
Posted: Tue Feb 02, 2021 6:43 am
by amrsherif
Great. Thank you