Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Working With Dates

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 07-03-2018 12:31 PM
(633 views)

Hi All,

I have a question on restricting dates. I have columns like so -- "Date", "Price", "Tflag". Wherever the "Tflag" column = '***', I would like to take the range of T+2 and T-2 for date. What i did originally was create lags(one ascending, one descending) of Date and created two new variables Date1 and Date2. This created the correct range on each tflag = ***. But i cannot figure out how to restrict my Date column by this range I created. Also, it is important to note that we are dealing with Trading Days and not just standard days. I say this because if a Tflag is on 6/25/2018 then the t-2 day would be 6/21/2018 and t+2 would be 6/27/2018. This would encompass a total of five dates, which it always should be unless there is significant days in a row.

Thanks.

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Have you looked at INTNX with the WEEKDAY option? Though you may want to create your own calendar to account for the unique calendar.

Otherwise, a SQL self join usually works, and/or using PROC EXPAND to calculate a moving statistics with the CONVERT statement.

@jrdykstr93 wrote:

Hi All,

I have a question on restricting dates. I have columns like so -- "Date", "Price", "Tflag". Wherever the "Tflag" column = '***', I would like to take the range of T+2 and T-2 for date. What i did originally was create lags(one ascending, one descending) of Date and created two new variables Date1 and Date2. This created the correct range on each tflag = ***. But i cannot figure out how to restrict my Date column by this range I created. Also, it is important to note that we are dealing with Trading Days and not just standard days. I say this because if a Tflag is on 6/25/2018 then the t-2 day would be 6/21/2018 and t+2 would be 6/27/2018. This would encompass a total of five dates, which it always should be unless there is significant days in a row.

Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

My SQL knowledge is embarrassing. But I will look into proc expand. Thanks.l

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You have omitted critical information.

How do you want to account for holidays? SAS can detect weekdays, but you need to somehow supply the holiday information.

What is the order to the observations? Do the observations you want to select fall both before and after the observation where tflag is *** ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

So if T-1 is a holiday, you still want T-2 to T+2? Not T-3 to T+2?

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

What is Bayesian Analysis?

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.