<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: pick data if  price higher than previous price in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66194#M18889</link>
    <description>I am confused totally. It would be better to show what your output  looks like.&lt;BR /&gt;
if you only want the highest strike price, no matter with the settle price &amp;lt; previous maximum strike price.Only one sql statement can get it.&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table want as&lt;BR /&gt;
  select *&lt;BR /&gt;
   from data1 &lt;BR /&gt;
    group by date&lt;BR /&gt;
     having Strike_Price=max(Strike_Price)&lt;BR /&gt;
    ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Ksharp&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Ksharp

Message was edited by: Ksharp</description>
    <pubDate>Thu, 19 May 2011 09:58:27 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-05-19T09:58:27Z</dc:date>
    <item>
      <title>pick data if  price higher than previous price</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66187#M18882</link>
      <description>I will face one of the four situation below every trading day. &lt;BR /&gt;
1. Keep the old contract and no need to buy a new contract.&lt;BR /&gt;
2. Sell the old contract ,and buy a new contract with a new strike price.&lt;BR /&gt;
3. When exdate minus date equal seven, I sell the old contract and buy a new contract with the same strike price.&lt;BR /&gt;
4. Same as three, but the nearest At-The-Money has the different strike price ,so I sell the old contract and buy a new one with the new strike price.&lt;BR /&gt;
&lt;BR /&gt;
How can I combine the four situations into one code?&lt;BR /&gt;
&lt;BR /&gt;
Data data1;&lt;BR /&gt;
input Date : yymmdd10. Exdate : yymmdd10. CP_FLAG $  Volum Strike_Price Settle_Price ;&lt;BR /&gt;
format date yymmdd10. exdate :yymmdd10. ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2008/1/2 2008/1/16 C  200 27.0 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P 300 27.0 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 C  552 22.5 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P  561 22.5 23.15&lt;BR /&gt;
2008/1/3 2008/1/16 C  756 25.0 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P  654 25.0 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 C  783 22.5 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P  150 22.5 23.42&lt;BR /&gt;
2008/1/4 2008/1/16 C  276 22.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P  246 22.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 C  276 25.0 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P  221 25.0 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 C  344 27.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P  476 27.5 27.00&lt;BR /&gt;
2008/1/5 2008/1/16 C  222 22.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P  343 22.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 C  768 25.0 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P  343 25.0 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 C  213 27.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P  343 27.5 24.00&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
data for question 3&lt;BR /&gt;
2008/1/9 2008/1/16 C  393 27.5 24.10&lt;BR /&gt;
2008/1/9 2008/1/16 P  493 27.5 24.10&lt;BR /&gt;
2008/1/9 2008/2/15 C  293 25.5 24.10&lt;BR /&gt;
2008/1/9 2008/2/15 P  693 25.5 24.10&lt;BR /&gt;
2008/1/9 2008/2/15 C  293 27.5 24.10&lt;BR /&gt;
2008/1/9 2008/2/15 P  593 27.5 24.10&lt;BR /&gt;
&lt;BR /&gt;
data for question 4&lt;BR /&gt;
2008/1/9 2008/1/16 C  393 27.5 29.10&lt;BR /&gt;
2008/1/9 2008/1/16 P  493 27.5 29.10&lt;BR /&gt;
2008/1/9 2008/2/15 C  293 27.5 29.10&lt;BR /&gt;
2008/1/9 2008/2/15 P  693 27.5 29.10&lt;BR /&gt;
2008/1/9 2008/2/15 C  293 30.0 29.10&lt;BR /&gt;
2008/1/9 2008/2/15 P  593 30.0 29.10&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
According to my previous question, i select contract when min{ABS(strike_price-settle_price)}.&lt;BR /&gt;
&lt;BR /&gt;
Question1: At 1/4 i should choice the contract which has strike_price for 27.5.&lt;BR /&gt;
The MIN{ABS()} only 0.5.  I also want keep the contract that has strike_price for &lt;BR /&gt;
22.5 at 1/4.  When I buy new contract I should sell old contract at 1/4. &lt;BR /&gt;
Can I keep the contract that has old strike_price and old exdate  every time when i buy new contract.&lt;BR /&gt;
&lt;BR /&gt;
Question2:&lt;BR /&gt;
 If settle price not bigger than previous maximum strike_price like 1/5, i just keep the contract which has  old strike_price and old exdate at  new date.&lt;BR /&gt;
At 1/5 i just retain the data&lt;BR /&gt;
&lt;BR /&gt;
2008/1/5 2008/1/16 C  213 27.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P  343 27.5 24.00&lt;BR /&gt;
&lt;BR /&gt;
Question3:&lt;BR /&gt;
If the date is seven days before Exdate.(date=2008/1/9  exdate=2008/1/16)&lt;BR /&gt;
No matter settle_price bigger than previous maximum strike_price.&lt;BR /&gt;
I need to change the contract that i hold to the new contract which has new exdate at next month. At 1/9 i want  &lt;BR /&gt;
the data like example below&lt;BR /&gt;
&lt;BR /&gt;
2008/1/9 2008/1/16 C  393 27.5 24.10&lt;BR /&gt;
2008/1/9 2008/1/16 P  493 27.5 24.10&lt;BR /&gt;
2008/1/9 2008/2/15 C  293 27.5 24.10&lt;BR /&gt;
2008/1/9 2008/2/15 P  593 27.5 24.10 &lt;BR /&gt;
&lt;BR /&gt;
Question(4)&lt;BR /&gt;
If settle_price &amp;gt; previous maximum strike_price at 1/9 &lt;BR /&gt;
We buy the new contract that has new strike_price with exdate an next month.&lt;BR /&gt;
I want the data as follows.&lt;BR /&gt;
&lt;BR /&gt;
2008/1/9 2008/1/16 C  393 27.5 29.10&lt;BR /&gt;
2008/1/9 2008/1/16 P  493 27.5 29.10&lt;BR /&gt;
2008/1/9 2008/2/15 C  293 30.0 29.10&lt;BR /&gt;
2008/1/9 2008/2/15 P  593 30.0 29.10&lt;BR /&gt;
&lt;BR /&gt;
I know this question is very complex.&lt;BR /&gt;
But plz help. Thank you very very very very much.&lt;BR /&gt;
&lt;BR /&gt;
                                                                          To SAS HERO

Message was edited by: RemusWayne</description>
      <pubDate>Mon, 16 May 2011 21:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66187#M18882</guid>
      <dc:creator>RemusWayne</dc:creator>
      <dc:date>2011-05-16T21:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: pick data if  price higher than previous price</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66188#M18883</link>
      <description>OK. I hope I am that SAS HERO. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
But for your Question  3 is ambiguous,I am not understand totally.&lt;BR /&gt;
Question one:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Data data1;&lt;BR /&gt;
input Date : yymmdd10. Exdate : yymmdd10. CP_FLAG $ Volum Strike_Price Settle_Price ;&lt;BR /&gt;
format date yymmdd10. exdate :yymmdd10. ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2008/1/2 2008/1/16 C 200 27.0 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P 300 27.0 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 C 552 22.5 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P 561 22.5 23.15&lt;BR /&gt;
2008/1/3 2008/1/16 C 756 25.0 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P 654 25.0 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 C 783 22.5 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P 150 22.5 23.42&lt;BR /&gt;
2008/1/4 2008/1/16 C 276 22.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 246 22.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 C 276 25.0 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 221 25.0 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 C 344 27.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 476 27.5 27.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 222 22.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 22.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 768 25.0 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 25.0 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 213 27.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 27.5 24.00&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table want as&lt;BR /&gt;
  select *&lt;BR /&gt;
   from data1 &lt;BR /&gt;
    group by date&lt;BR /&gt;
     having abs(Strike_Price-Settle_Price) =&lt;BR /&gt;
            min(abs(Strike_Price-Settle_Price))&lt;BR /&gt;
    ;&lt;BR /&gt;
quit;&lt;BR /&gt;
proc sort data=want nodupkey out=op1(keep=date strike_price);&lt;BR /&gt;
 by date strike_price;&lt;BR /&gt;
run;&lt;BR /&gt;
data op1;&lt;BR /&gt;
 set op1;&lt;BR /&gt;
 _strike_price=lag(strike_price);&lt;BR /&gt;
 drop strike_price;&lt;BR /&gt;
run;&lt;BR /&gt;
data temp(where=(strike_price=_strike_price));&lt;BR /&gt;
 merge data1 op1;&lt;BR /&gt;
 by date;&lt;BR /&gt;
 ;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
data want;&lt;BR /&gt;
 set want temp(drop=_strike_price);&lt;BR /&gt;
 by date;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Question Two:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Data data1;&lt;BR /&gt;
input Date : yymmdd10. Exdate : yymmdd10. CP_FLAG $ Volum Strike_Price Settle_Price ;&lt;BR /&gt;
format date yymmdd10. exdate :yymmdd10. ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2008/1/2 2008/1/16 C 200 27.0 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P 300 27.0 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 C 552 22.5 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P 561 22.5 23.15&lt;BR /&gt;
2008/1/3 2008/1/16 C 756 25.0 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P 654 25.0 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 C 783 22.5 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P 150 22.5 23.42&lt;BR /&gt;
2008/1/4 2008/1/16 C 276 22.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 246 22.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 C 276 25.0 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 221 25.0 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 C 344 27.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 476 27.5 27.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 222 22.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 22.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 768 25.0 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 25.0 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 213 27.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 27.5 24.00&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table temp as&lt;BR /&gt;
  select *,max(strike_price) as max_strike&lt;BR /&gt;
   from data1 &lt;BR /&gt;
    group by date&lt;BR /&gt;
     having abs(Strike_Price-Settle_Price) =&lt;BR /&gt;
            min(abs(Strike_Price-Settle_Price))&lt;BR /&gt;
    ;&lt;BR /&gt;
quit;&lt;BR /&gt;
proc sort data=temp nodupkey out=op(keep=date max_strike Strike_Price);&lt;BR /&gt;
 by date max_strike;&lt;BR /&gt;
run;&lt;BR /&gt;
data op;&lt;BR /&gt;
 set op;&lt;BR /&gt;
 lag_max_strike=lag(max_strike);&lt;BR /&gt;
 _Strike_Price=lag(Strike_Price);&lt;BR /&gt;
 drop max_strike Strike_Price;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want ;&lt;BR /&gt;
 merge data1 op;&lt;BR /&gt;
 by date;&lt;BR /&gt;
 if Settle_Price le lag_max_strike and _Strike_Price=Strike_Price&lt;BR /&gt;
  then output;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Question Three:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Data data1;&lt;BR /&gt;
input Date : yymmdd10. Exdate : yymmdd10. CP_FLAG $ Volum Strike_Price Settle_Price ;&lt;BR /&gt;
format date yymmdd10. exdate :yymmdd10. ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2008/1/10 2008/1/16 C 393 27.5 24.10&lt;BR /&gt;
2008/1/10 2008/1/16 P 493 27.5 24.10&lt;BR /&gt;
2008/1/10 2008/2/15 C 293 25.5 24.10&lt;BR /&gt;
2008/1/10 2008/2/15 P 693 25.5 24.10&lt;BR /&gt;
2008/1/10 2008/2/15 C 293 27.5 24.10&lt;BR /&gt;
2008/1/10 2008/2/15 P 593 27.5 24.10&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table temp as&lt;BR /&gt;
  select *&lt;BR /&gt;
   from data1 &lt;BR /&gt;
    where exdate-date ge 5&lt;BR /&gt;
      group by date,exdate&lt;BR /&gt;
        having abs(Strike_Price-Settle_Price) =&lt;BR /&gt;
            min(abs(Strike_Price-Settle_Price))&lt;BR /&gt;
    ;&lt;BR /&gt;
quit;&lt;BR /&gt;
proc sort data=temp nodupkey out=op(keep=date exdate strike_price);&lt;BR /&gt;
 by date exdate;&lt;BR /&gt;
run;&lt;BR /&gt;
data op;&lt;BR /&gt;
 set op;&lt;BR /&gt;
 _strike_price=lag(strike_price);&lt;BR /&gt;
 if _n_ =1 then  _strike_price=strike_price;&lt;BR /&gt;
 drop strike_price;&lt;BR /&gt;
run;&lt;BR /&gt;
data want;&lt;BR /&gt;
 merge data1 op;&lt;BR /&gt;
 by date exdate;&lt;BR /&gt;
 if _strike_price=strike_price;&lt;BR /&gt;
 drop _strike_price;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Question Four:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Data data1;&lt;BR /&gt;
input Date : yymmdd10. Exdate : yymmdd10. CP_FLAG $ Volum Strike_Price Settle_Price ;&lt;BR /&gt;
format date yymmdd10. exdate :yymmdd10. ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2008/1/10 2008/1/16 C 393 27.5 29.10&lt;BR /&gt;
2008/1/10 2008/1/16 P 493 27.5 29.10&lt;BR /&gt;
2008/1/10 2008/2/15 C 293 27.5 29.10&lt;BR /&gt;
2008/1/10 2008/2/15 P 693 27.5 29.10&lt;BR /&gt;
2008/1/10 2008/2/15 C 293 30.0 29.10&lt;BR /&gt;
2008/1/10 2008/2/15 P 593 30.0 29.10&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table temp as&lt;BR /&gt;
  select *,max(strike_price) as max_strike&lt;BR /&gt;
   from data1 &lt;BR /&gt;
    group by date,exdate&lt;BR /&gt;
     having abs(Strike_Price-Settle_Price) =&lt;BR /&gt;
            min(abs(Strike_Price-Settle_Price))&lt;BR /&gt;
    ;&lt;BR /&gt;
quit;&lt;BR /&gt;
proc sort data=temp nodupkey out=op(keep=date exdate max_strike );&lt;BR /&gt;
 by date exdate max_strike;&lt;BR /&gt;
run;&lt;BR /&gt;
data op;&lt;BR /&gt;
 set op;&lt;BR /&gt;
 lag_max_strike=lag(max_strike);&lt;BR /&gt;
 drop max_strike ;&lt;BR /&gt;
run;&lt;BR /&gt;
data want;&lt;BR /&gt;
 merge data1 op;&lt;BR /&gt;
 by date exdate;&lt;BR /&gt;
 if  strike_price ne lag_max_strike;&lt;BR /&gt;
 drop lag_max_strike; &lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 18 May 2011 06:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66188#M18883</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-18T06:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: pick data if  price higher than previous price</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66189#M18884</link>
      <description>Yes , you are my SAS hero. THANK YOU !!&lt;BR /&gt;
&lt;BR /&gt;
Sorry to say that I have posted some wrong data here.&lt;BR /&gt;
I've re-edited it above.&lt;BR /&gt;
&lt;BR /&gt;
I've learned a lot from your reply and they are very much helping.&lt;BR /&gt;
However, I still have some confusing questions.&lt;BR /&gt;
&lt;BR /&gt;
The date we have here are continuous running throughout the year.&lt;BR /&gt;
So, I was wondering if SAS can combine the four situation into one table for me to check everyday's data.&lt;BR /&gt;
&lt;BR /&gt;
RemusWayne</description>
      <pubDate>Wed, 18 May 2011 08:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66189#M18884</guid>
      <dc:creator>RemusWayne</dc:creator>
      <dc:date>2011-05-18T08:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: pick data if  price higher than previous price</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66190#M18885</link>
      <description>I think answer is yes.But need more time to consider these situation and think how to code it If you want.&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 18 May 2011 10:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66190#M18885</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-18T10:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: pick data if  price higher than previous price</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66191#M18886</link>
      <description>2008/1/2 2008/1/16 C 200 27.0 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P 300 27.0 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 C 552 22.5 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P 561 22.5 23.15&lt;BR /&gt;
2008/1/3 2008/1/16 C 756 25.0 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P 654 25.0 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 C 783 22.5 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P 150 22.5 23.42&lt;BR /&gt;
2008/1/4 2008/1/16 C 276 22.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 246 22.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 C 276 25.0 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 221 25.0 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 C 344 27.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 476 27.5 27.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 222 22.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 22.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 768 25.0 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 25.0 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 213 27.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 27.5 24.00&lt;BR /&gt;
2008/1/6 2008/1/16 C 234 25.0 24.50&lt;BR /&gt;
2008/1/6 2008/1/16 P 235 25.0 24.50&lt;BR /&gt;
2008/1/6 2008/1/16 C 345 27.5 24.50&lt;BR /&gt;
2008/1/6 2008/1/16 P 368 27.5 24.50&lt;BR /&gt;
 &lt;BR /&gt;
I have modified Question1&lt;BR /&gt;
 &lt;BR /&gt;
I want to lock in the high strike price of my database&lt;BR /&gt;
At 1/5 the settle price  &amp;lt; previous maximum strike price(27.5)&lt;BR /&gt;
I want to keep the contract with the maximum strike price but not  &lt;BR /&gt;
at-the-money  at 1/5&lt;BR /&gt;
The following data is what I want to keep &lt;BR /&gt;
2008/1/2 2008/1/16 C 552 22.5 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P 561 22.5 23.15&lt;BR /&gt;
2008/1/3 2008/1/16 C 783 22.5 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P 150 22.5 23.42&lt;BR /&gt;
2008/1/4 2008/1/16 C 344 27.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 476 27.5 27.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 213 27.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 27.5 24.00&lt;BR /&gt;
2008/1/6 2008/1/16 C 345 27.5 24.50&lt;BR /&gt;
2008/1/6 2008/1/16 P 368 27.5 24.50 &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.</description>
      <pubDate>Wed, 18 May 2011 12:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66191#M18886</guid>
      <dc:creator>RemusWayne</dc:creator>
      <dc:date>2011-05-18T12:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: pick data if  price higher than previous price</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66192#M18887</link>
      <description>OK.&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Data data1;&lt;BR /&gt;
input Date : yymmdd10. Exdate : yymmdd10. CP_FLAG $ Volum Strike_Price Settle_Price ;&lt;BR /&gt;
format date yymmdd10. exdate :yymmdd10. ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2008/1/2 2008/1/16 C 200 27.0 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P 300 27.0 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 C 552 22.5 23.15&lt;BR /&gt;
2008/1/2 2008/1/16 P 561 22.5 23.15&lt;BR /&gt;
2008/1/3 2008/1/16 C 756 25.0 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P 654 25.0 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 C 783 22.5 23.42&lt;BR /&gt;
2008/1/3 2008/1/16 P 150 22.5 23.42&lt;BR /&gt;
2008/1/4 2008/1/16 C 276 22.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 246 22.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 C 276 25.0 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 221 25.0 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 C 344 27.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 476 27.5 27.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 222 22.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 22.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 768 25.0 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 25.0 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 C 213 27.5 24.00&lt;BR /&gt;
2008/1/5 2008/1/16 P 343 27.5 24.00&lt;BR /&gt;
2008/1/6 2008/1/16 C 234 25.0 24.50&lt;BR /&gt;
2008/1/6 2008/1/16 P 235 25.0 24.50&lt;BR /&gt;
2008/1/6 2008/1/16 C 345 27.5 24.50&lt;BR /&gt;
2008/1/6 2008/1/16 P 368 27.5 24.50&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table temp as&lt;BR /&gt;
  select *,max(strike_price) as max_strike&lt;BR /&gt;
   from data1 &lt;BR /&gt;
    group by date&lt;BR /&gt;
     having abs(Strike_Price-Settle_Price) =&lt;BR /&gt;
            min(abs(Strike_Price-Settle_Price))&lt;BR /&gt;
    ;&lt;BR /&gt;
quit;&lt;BR /&gt;
proc sort data=temp nodupkey out=op(keep=date max_strike Strike_Price);&lt;BR /&gt;
 by date max_strike;&lt;BR /&gt;
run;&lt;BR /&gt;
data op;&lt;BR /&gt;
 set op;&lt;BR /&gt;
 lag_max_strike=lag(max_strike);&lt;BR /&gt;
 _Strike_Price=lag(Strike_Price);&lt;BR /&gt;
 drop max_strike Strike_Price;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data _want ;&lt;BR /&gt;
 merge data1 op;&lt;BR /&gt;
 by date;&lt;BR /&gt;
 if Settle_Price le lag_max_strike ;&lt;BR /&gt;
 drop  lag_max_strike _Strike_Price;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table want as&lt;BR /&gt;
  select *&lt;BR /&gt;
   from _want &lt;BR /&gt;
    group by date&lt;BR /&gt;
     having Strike_Price=max(Strike_Price)&lt;BR /&gt;
    ;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Thu, 19 May 2011 01:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66192#M18887</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-19T01:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: pick data if  price higher than previous price</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66193#M18888</link>
      <description>Thank you very much.&lt;BR /&gt;
&lt;BR /&gt;
I want to lock in the high strike price of my database&lt;BR /&gt;
At 1/5 the settle price &amp;lt; previous maximum strike price(27.5)&lt;BR /&gt;
I want to keep the contract with the" maximum strike price" but not &lt;BR /&gt;
at-the-money at 1/5&lt;BR /&gt;
&lt;BR /&gt;
maximum strike price ==&amp;gt;   I redefined it= The  closest contract's strike price&lt;BR /&gt;
&lt;BR /&gt;
At 1/5 the closest contract is   contract with strike price 27.5  at 1/4&lt;BR /&gt;
&lt;BR /&gt;
At 1/6  the closest contract is   contract with strike price 27.5  at 1/4&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I Follow your code but the answer lack of data at 1/4.&lt;BR /&gt;
2008/1/4 2008/1/16 C 344 27.5 27.00&lt;BR /&gt;
2008/1/4 2008/1/16 P 476 27.5 27.00</description>
      <pubDate>Thu, 19 May 2011 03:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66193#M18888</guid>
      <dc:creator>RemusWayne</dc:creator>
      <dc:date>2011-05-19T03:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: pick data if  price higher than previous price</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66194#M18889</link>
      <description>I am confused totally. It would be better to show what your output  looks like.&lt;BR /&gt;
if you only want the highest strike price, no matter with the settle price &amp;lt; previous maximum strike price.Only one sql statement can get it.&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table want as&lt;BR /&gt;
  select *&lt;BR /&gt;
   from data1 &lt;BR /&gt;
    group by date&lt;BR /&gt;
     having Strike_Price=max(Strike_Price)&lt;BR /&gt;
    ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Ksharp&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Thu, 19 May 2011 09:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-data-if-price-higher-than-previous-price/m-p/66194#M18889</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-19T09:58:27Z</dc:date>
    </item>
  </channel>
</rss>

