checking if date is last weekday of the month

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

amrsherif
Posts: 109
Joined: Mon Jul 23, 2018 4:34 pm

checking if date is last weekday of the month

Postby amrsherif » Mon Feb 01, 2021 12:59 pm

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

Re: checking if date is last weekday of the month

Postby EViews Gareth » Mon Feb 01, 2021 1:17 pm

Code: Select all

smpl if @month<>@month(1) alpha mydate = @datestr(@date, "YYYY-MM-DD") svector lastdates =@uniquevals(mydate)

amrsherif
Posts: 109
Joined: Mon Jul 23, 2018 4:34 pm

Re: checking if date is last weekday of the month

Postby amrsherif » Mon Feb 01, 2021 2:16 pm

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

Re: checking if date is last weekday of the month

Postby EViews Gareth » Mon Feb 01, 2021 3:34 pm

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

Re: checking if date is last weekday of the month

Postby EViews Gareth » Mon Feb 01, 2021 3:42 pm

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)

amrsherif
Posts: 109
Joined: Mon Jul 23, 2018 4:34 pm

Re: checking if date is last weekday of the month

Postby amrsherif » Tue Feb 02, 2021 6:43 am

Great. Thank you


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests