BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Xinhui
Obsidian | Level 7

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. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
alexchien
Pyrite | Level 9

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;

View solution in original post

2 REPLIES 2
Xinhui
Obsidian | Level 7

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. 

 

alexchien
Pyrite | Level 9

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;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 703 views
  • 2 likes
  • 2 in conversation