turn on suggestions

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

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Forecasting
- /
- pick up nearest number from data set

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-01-2017 11:04 PM

In my case, we have three variables - the underlying price, the strike price, and the datadate. When the program picks up the strike price that is nearest to the underlying price, I also need it to consider the datadate. Please see the attached document for a sample.

So basically, I need it to pick the nearest strike price within that given date.

For example, on 2011/1/16, the underlying price is 26.33. The closest strike price is 26.5.

On 2011/1/17, the underlying price is 26.11 and the closest strike price is 26.

Accepted Solutions

Solution

03-15-2017
11:30 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Xinhui

03-02-2017 10:24 AM

If the underlying_price is a constant within a day, you can use a sort and data step to get the nearest strike price.

data sample_new;

set sample;

diff = abs(underlying_price - strike);

run;

proc sort data = sample_new;

by datadate diff;

run;

data nearest_price;

set sample_new;

by datadate diff;

if first.datadate;

run;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Xinhui

03-01-2017 11:04 PM

In my case, we have three variables - the underlying price, the strike price, and the datadate. When the program picks up the strike price that is nearest to the underlying price, I also need it to consider the datadate. Please see the attached document for a sample.

So basically, I need it to pick the nearest strike price within that given date.

For example, on 2011/1/16, the underlying price is 26.33. The closest strike price is 26.5.

On 2011/1/17, the underlying price is 26.11 and the closest strike price is 26.

Solution

03-15-2017
11:30 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Xinhui

03-02-2017 10:24 AM

If the underlying_price is a constant within a day, you can use a sort and data step to get the nearest strike price.

data sample_new;

set sample;

diff = abs(underlying_price - strike);

run;

proc sort data = sample_new;

by datadate diff;

run;

data nearest_price;

set sample_new;

by datadate diff;

if first.datadate;

run;