<?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 the first and last in a group in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/the-first-and-last-in-a-group/m-p/66224#M18892</link>
    <description>i have a data1 like following.&lt;BR /&gt;
 &lt;BR /&gt;
i want to do following step&lt;BR /&gt;
&lt;BR /&gt;
1. see the last day in the different optionid group.&lt;BR /&gt;
   if the  OTM &amp;gt; 0.1 then output dataA&lt;BR /&gt;
   else output dataB&lt;BR /&gt;
&lt;BR /&gt;
2. in dataA and dataB, &lt;BR /&gt;
     the hold =absolute value of the delta &lt;BR /&gt;
&lt;BR /&gt;
3. , the AAA is the hold -lag(hold) at the first day in the optionid group&lt;BR /&gt;
       in dataA, the AAA is AAA+strike_price&lt;BR /&gt;
       in dataB, the AAA is remained.&lt;BR /&gt;
&lt;BR /&gt;
please help me thanks~~&lt;BR /&gt;
&lt;BR /&gt;
 the result is as following&lt;BR /&gt;
&lt;BR /&gt;
data data1;&lt;BR /&gt;
input date: yymmdd10.	optionid	SPXClose	strike_price	delta	OTM	;&lt;BR /&gt;
format date yymmdd10.  ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2004/1/2	21213832	1108.48	995	-0.030962	0.002374423&lt;BR /&gt;
2004/1/5	21213832	1122.22	995	-0.015296	0.013364581&lt;BR /&gt;
2004/1/6	21213832	1123.67	995	-0.013465	0.014508708&lt;BR /&gt;
2004/1/7	21213832	1126.33	995	-0.009658	0.016599931&lt;BR /&gt;
2004/1/8	21213832	1131.92	995	-0.009319	0.020962612&lt;BR /&gt;
2004/1/9	21213832	1121.86	995	-0.008953	0.013080064&lt;BR /&gt;
2004/1/12	21213832	1127.23	995	-0.004376	0.017305253&lt;BR /&gt;
2004/1/13	21213832	1121.22	995	-0.005754	0.012573804&lt;BR /&gt;
2004/1/14	21213832	1130.52	995	0	0.01987404&lt;BR /&gt;
2004/1/15	21213832	1132.05	995	0	0.021063557		&lt;BR /&gt;
2008/1/8	21238884	1390.19	1340	-0.180018	0.063897021&lt;BR /&gt;
2008/1/9	21238884	1409.13	1340	-0.099134	0.050941361&lt;BR /&gt;
2008/1/10	21238884	1420.33	1340	-0.067354	0.043442721&lt;BR /&gt;
2008/1/11	21238884	1401.02	1340	-0.063845	0.056446018&lt;BR /&gt;
2008/1/14	21238884	1416.25	1340	-0.026838	0.046160635&lt;BR /&gt;
2008/1/15	21238884	1380.95	1340	-0.101002	0.070346501&lt;BR /&gt;
2008/1/16	21238884	1373.2	1340	-0.126768	0.075822895&lt;BR /&gt;
2008/1/17	21238884	1333.25	1340	-1	0.105062816&lt;BR /&gt;
&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data dataA;&lt;BR /&gt;
input date: yymmdd10.	optionid	SPXClose	strike_price	delta	OTM hold	AAA;&lt;BR /&gt;
format date yymmdd10.  ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2004/1/2	21213832	1108.48	995	-0.030962	0.002374423	0.030962	0.030962&lt;BR /&gt;
2004/1/5	21213832	1122.22	995	-0.015296	0.013364581	0.015296	-0.015666&lt;BR /&gt;
2004/1/6	21213832	1123.67	995	-0.013465	0.014508708	0.013465	-0.001831&lt;BR /&gt;
2004/1/7	21213832	1126.33	995	-0.009658	0.016599931	0.009658	-0.003807&lt;BR /&gt;
2004/1/8	21213832	1131.92	995	-0.009319	0.020962612	0.009319	-0.000339&lt;BR /&gt;
2004/1/9	21213832	1121.86	995	-0.008953	0.013080064	0.008953	-0.000366&lt;BR /&gt;
2004/1/12	21213832	1127.23	995	-0.004376	0.017305253	0.004376	-0.004577&lt;BR /&gt;
2004/1/13	21213832	1121.22	995	-0.005754	0.012573804	0.005754	0.001378&lt;BR /&gt;
2004/1/14	21213832	1130.52	995	0	0.01987404	0	-0.005754&lt;BR /&gt;
2004/1/15	21213832	1132.05	995	0	0.021063557	0	995&lt;BR /&gt;
&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data dataB;&lt;BR /&gt;
input date: yymmdd10.	optionid	SPXClose	strike_price	delta	OTM hold	AAA;&lt;BR /&gt;
format date yymmdd10.  ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2008/1/8	21238884	1390.19	1340	-0.180018	0.063897021	0.180018	0.180018&lt;BR /&gt;
2008/1/9	21238884	1409.13	1340	-0.099134	0.050941361	0.099134	-0.080884&lt;BR /&gt;
2008/1/10	21238884	1420.33	1340	-0.067354	0.043442721	0.067354	-0.03178&lt;BR /&gt;
2008/1/11	21238884	1401.02	1340	-0.063845	0.056446018	0.063845	-0.003509&lt;BR /&gt;
2008/1/14	21238884	1416.25	1340	-0.026838	0.046160635	0.026838	-0.037007&lt;BR /&gt;
2008/1/15	21238884	1380.95	1340	-0.101002	0.070346501	0.101002	0.074164&lt;BR /&gt;
2008/1/16	21238884	1373.2	1340	-0.126768	0.075822895	0.126768	0.025766&lt;BR /&gt;
2008/1/17	21238884	1333.25	1340	-1	0.105062816	1	0.873232&lt;BR /&gt;
&lt;BR /&gt;
;&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 17 May 2011 11:30:47 GMT</pubDate>
    <dc:creator>bqk</dc:creator>
    <dc:date>2011-05-17T11:30:47Z</dc:date>
    <item>
      <title>the first and last in a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/the-first-and-last-in-a-group/m-p/66224#M18892</link>
      <description>i have a data1 like following.&lt;BR /&gt;
 &lt;BR /&gt;
i want to do following step&lt;BR /&gt;
&lt;BR /&gt;
1. see the last day in the different optionid group.&lt;BR /&gt;
   if the  OTM &amp;gt; 0.1 then output dataA&lt;BR /&gt;
   else output dataB&lt;BR /&gt;
&lt;BR /&gt;
2. in dataA and dataB, &lt;BR /&gt;
     the hold =absolute value of the delta &lt;BR /&gt;
&lt;BR /&gt;
3. , the AAA is the hold -lag(hold) at the first day in the optionid group&lt;BR /&gt;
       in dataA, the AAA is AAA+strike_price&lt;BR /&gt;
       in dataB, the AAA is remained.&lt;BR /&gt;
&lt;BR /&gt;
please help me thanks~~&lt;BR /&gt;
&lt;BR /&gt;
 the result is as following&lt;BR /&gt;
&lt;BR /&gt;
data data1;&lt;BR /&gt;
input date: yymmdd10.	optionid	SPXClose	strike_price	delta	OTM	;&lt;BR /&gt;
format date yymmdd10.  ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2004/1/2	21213832	1108.48	995	-0.030962	0.002374423&lt;BR /&gt;
2004/1/5	21213832	1122.22	995	-0.015296	0.013364581&lt;BR /&gt;
2004/1/6	21213832	1123.67	995	-0.013465	0.014508708&lt;BR /&gt;
2004/1/7	21213832	1126.33	995	-0.009658	0.016599931&lt;BR /&gt;
2004/1/8	21213832	1131.92	995	-0.009319	0.020962612&lt;BR /&gt;
2004/1/9	21213832	1121.86	995	-0.008953	0.013080064&lt;BR /&gt;
2004/1/12	21213832	1127.23	995	-0.004376	0.017305253&lt;BR /&gt;
2004/1/13	21213832	1121.22	995	-0.005754	0.012573804&lt;BR /&gt;
2004/1/14	21213832	1130.52	995	0	0.01987404&lt;BR /&gt;
2004/1/15	21213832	1132.05	995	0	0.021063557		&lt;BR /&gt;
2008/1/8	21238884	1390.19	1340	-0.180018	0.063897021&lt;BR /&gt;
2008/1/9	21238884	1409.13	1340	-0.099134	0.050941361&lt;BR /&gt;
2008/1/10	21238884	1420.33	1340	-0.067354	0.043442721&lt;BR /&gt;
2008/1/11	21238884	1401.02	1340	-0.063845	0.056446018&lt;BR /&gt;
2008/1/14	21238884	1416.25	1340	-0.026838	0.046160635&lt;BR /&gt;
2008/1/15	21238884	1380.95	1340	-0.101002	0.070346501&lt;BR /&gt;
2008/1/16	21238884	1373.2	1340	-0.126768	0.075822895&lt;BR /&gt;
2008/1/17	21238884	1333.25	1340	-1	0.105062816&lt;BR /&gt;
&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data dataA;&lt;BR /&gt;
input date: yymmdd10.	optionid	SPXClose	strike_price	delta	OTM hold	AAA;&lt;BR /&gt;
format date yymmdd10.  ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2004/1/2	21213832	1108.48	995	-0.030962	0.002374423	0.030962	0.030962&lt;BR /&gt;
2004/1/5	21213832	1122.22	995	-0.015296	0.013364581	0.015296	-0.015666&lt;BR /&gt;
2004/1/6	21213832	1123.67	995	-0.013465	0.014508708	0.013465	-0.001831&lt;BR /&gt;
2004/1/7	21213832	1126.33	995	-0.009658	0.016599931	0.009658	-0.003807&lt;BR /&gt;
2004/1/8	21213832	1131.92	995	-0.009319	0.020962612	0.009319	-0.000339&lt;BR /&gt;
2004/1/9	21213832	1121.86	995	-0.008953	0.013080064	0.008953	-0.000366&lt;BR /&gt;
2004/1/12	21213832	1127.23	995	-0.004376	0.017305253	0.004376	-0.004577&lt;BR /&gt;
2004/1/13	21213832	1121.22	995	-0.005754	0.012573804	0.005754	0.001378&lt;BR /&gt;
2004/1/14	21213832	1130.52	995	0	0.01987404	0	-0.005754&lt;BR /&gt;
2004/1/15	21213832	1132.05	995	0	0.021063557	0	995&lt;BR /&gt;
&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data dataB;&lt;BR /&gt;
input date: yymmdd10.	optionid	SPXClose	strike_price	delta	OTM hold	AAA;&lt;BR /&gt;
format date yymmdd10.  ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2008/1/8	21238884	1390.19	1340	-0.180018	0.063897021	0.180018	0.180018&lt;BR /&gt;
2008/1/9	21238884	1409.13	1340	-0.099134	0.050941361	0.099134	-0.080884&lt;BR /&gt;
2008/1/10	21238884	1420.33	1340	-0.067354	0.043442721	0.067354	-0.03178&lt;BR /&gt;
2008/1/11	21238884	1401.02	1340	-0.063845	0.056446018	0.063845	-0.003509&lt;BR /&gt;
2008/1/14	21238884	1416.25	1340	-0.026838	0.046160635	0.026838	-0.037007&lt;BR /&gt;
2008/1/15	21238884	1380.95	1340	-0.101002	0.070346501	0.101002	0.074164&lt;BR /&gt;
2008/1/16	21238884	1373.2	1340	-0.126768	0.075822895	0.126768	0.025766&lt;BR /&gt;
2008/1/17	21238884	1333.25	1340	-1	0.105062816	1	0.873232&lt;BR /&gt;
&lt;BR /&gt;
;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 17 May 2011 11:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/the-first-and-last-in-a-group/m-p/66224#M18892</guid>
      <dc:creator>bqk</dc:creator>
      <dc:date>2011-05-17T11:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: the first and last in a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/the-first-and-last-in-a-group/m-p/66225#M18893</link>
      <description>Hello Bqk,&lt;BR /&gt;
&lt;BR /&gt;
If I understand you corretly this is a solution:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sort data=data1;&lt;BR /&gt;
  by optionid descending date;&lt;BR /&gt;
run;&lt;BR /&gt;
data dataA dataB;&lt;BR /&gt;
  retain out;&lt;BR /&gt;
  set data1;&lt;BR /&gt;
  if      FIRST.optionid and OTM GT 0.1 then out="A";&lt;BR /&gt;
  else if FIRST.optionid and OTM LE 0.1 then out="B";&lt;BR /&gt;
  if out="A" then output dataA;&lt;BR /&gt;
  if out="B" then output dataB;&lt;BR /&gt;
  by optionid;&lt;BR /&gt;
  drop out;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=dataA;&lt;BR /&gt;
  by optionid date;&lt;BR /&gt;
run;&lt;BR /&gt;
data ra;&lt;BR /&gt;
  retain lg;&lt;BR /&gt;
  set dataA;&lt;BR /&gt;
  hold=ABS(delta);&lt;BR /&gt;
  lg=LAG(hold);&lt;BR /&gt;
  if FIRST.optionid then do; AAA=hold; end;&lt;BR /&gt;
  else do; AAA=hold-lg; end;&lt;BR /&gt;
  by optionid;&lt;BR /&gt;
  drop lg;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=dataB;&lt;BR /&gt;
  by optionid date;&lt;BR /&gt;
run;&lt;BR /&gt;
data rb;&lt;BR /&gt;
  retain lg;&lt;BR /&gt;
  set dataB;&lt;BR /&gt;
  hold=ABS(delta);&lt;BR /&gt;
  lg=LAG(hold);&lt;BR /&gt;
  if FIRST.optionid then do; AAA=hold; end;&lt;BR /&gt;
  else do; AAA=hold-lg; end;&lt;BR /&gt;
  if LAST.optionid then AAA=AAA+strike_price; &lt;BR /&gt;
  by optionid;&lt;BR /&gt;
  drop lg;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
I should menthion than your condition &lt;BR /&gt;
"1. see the last day in the different optionid group. &lt;BR /&gt;
if the OTM &amp;gt; 0.1 then output dataA else output dataB"&lt;BR /&gt;
contradicts with the contents of your dataA and dataB. &lt;BR /&gt;
Also, it looks like your the "3. AAA is AAA+strike_price" applies to the last date for the current optionid.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Tue, 17 May 2011 14:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/the-first-and-last-in-a-group/m-p/66225#M18893</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-17T14:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: the first and last in a group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/the-first-and-last-in-a-group/m-p/66226#M18894</link>
      <description>i think it is wrong that i type the dataA and dataB&lt;BR /&gt;
&lt;BR /&gt;
it is true that  if OTM&amp;gt;0.1 then output dataB else output dataA.&lt;BR /&gt;
&lt;BR /&gt;
thank SPR much</description>
      <pubDate>Tue, 17 May 2011 16:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/the-first-and-last-in-a-group/m-p/66226#M18894</guid>
      <dc:creator>bqk</dc:creator>
      <dc:date>2011-05-17T16:07:58Z</dc:date>
    </item>
  </channel>
</rss>

