<?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 Macro in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macro/m-p/546120#M74342</link>
    <description>&lt;P&gt;I want to know how to run this program. in other word the data file name and the variable that I must include in the data&lt;/P&gt;
&lt;P&gt;/***********************************************************************/&lt;BR /&gt;/* */&lt;BR /&gt;/* Program: Option-Based Factors */&lt;BR /&gt;/* Author : Luis Palacios, WRDS */&lt;BR /&gt;/* Date : 03/01/2010 */&lt;BR /&gt;/* Revised : 03/29/2010 */&lt;BR /&gt;/* Steps : */&lt;BR /&gt;/* - Get Daily option prices for all S&amp;amp;P500 options */&lt;BR /&gt;/* - S&amp;amp;P500 (SPX) secid in optionmetrics is 108105 */&lt;BR /&gt;/* - Filters applied on 1st trading day of month */&lt;BR /&gt;/* - Keep options expiring in the following month */&lt;BR /&gt;/* - Keep only options with available prices */&lt;BR /&gt;/* - Keep options with standard settlements */&lt;BR /&gt;/* */&lt;BR /&gt;/* Notes on SPX Options: */&lt;BR /&gt;/* - Expiration: Saturday Following the 3rd Friday of Expiration Month */&lt;BR /&gt;/* - Exercise Style: European exercisable on last bus day bef. exp. */&lt;BR /&gt;/* */&lt;BR /&gt;/* Example: %optionfactor(begyear=1996,endyear=2009, */&lt;BR /&gt;/* flag=C,atm_otm=OTM,outfile=myfinalOTM); */&lt;BR /&gt;/* ******************************************************************* */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro optionfactor&lt;BR /&gt;(begyear=1996,endyear=2012,flag=C,atm_otm=OTM,outfile=myfinalOTM,sp500_id=108105);&lt;BR /&gt;&lt;BR /&gt;data a1;&lt;BR /&gt;set %do i=&amp;amp;begyear %to &amp;amp;endyear; OPTIONM.OPPRCD&amp;amp;i&lt;BR /&gt;(keep = date secid exdate strike_price best_bid best_offer optionid&lt;BR /&gt;exdate ss_flag cp_flag where = (secid=&amp;amp;sp500_id)) %end; ;&lt;BR /&gt;month = month(date);&lt;BR /&gt;year = year(date) ;&lt;BR /&gt;/* Keep Options with Standard Settlment, i.e. 0 Special. Settl. Flag */&lt;BR /&gt;if ss_flag='0' and cp_flag="&amp;amp;flag" and best_bid&amp;gt;0 and best_offer&amp;gt;0;&lt;BR /&gt;/* Mid-Price */&lt;BR /&gt;price = (best_bid + best_offer)/2;&lt;BR /&gt;/* Strike Price Adjustment */&lt;BR /&gt;strike=strike_price/1000;&lt;BR /&gt;/* Standard SPX option expire Saturday (weekday=7)following the third Friday of the expiration month */&lt;BR /&gt;if weekday(exdate)=7; * it eliminates non standard-date options;&lt;BR /&gt;drop ss_flag cp_flag best_bid best_offer strike_price;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* Sort Dataset to Keep First Observation per Month */&lt;BR /&gt;proc sort data=a1 out=a1; by optionid year month date; run;&lt;BR /&gt;&lt;BR /&gt;/* Use Data from the First Trading Day of the Month */&lt;BR /&gt;/* Keep only Options that Expire in the Following Month */&lt;BR /&gt;data a2; set a1;&lt;BR /&gt;by optionid year month date;&lt;BR /&gt;if first.month;&lt;BR /&gt;if intck('month',date,exdate)=1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Get Price of the underlying index (S&amp;amp;P 500) */&lt;BR /&gt;data b1;&lt;BR /&gt;set %do i=&amp;amp;begyear %to &amp;amp;endyear %by 1;&lt;BR /&gt;optionm.secprd&amp;amp;i (where = (secid=&amp;amp;sp500_id)) %end; ;&lt;BR /&gt;month = month(date);&lt;BR /&gt;year = year(date);&lt;BR /&gt;/* CLOSE is closing price at the end of the day */&lt;BR /&gt;keep date year month close secid;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Sort Price Data */&lt;BR /&gt;proc sort data=b1 out=b1; by secid year month date; run;&lt;BR /&gt;&lt;BR /&gt;/* Keep data on first day of the month */&lt;BR /&gt;data b2; set b1;&lt;BR /&gt;by secid year month date;&lt;BR /&gt;if first.month;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Add Risk-Free Rate for Present Value Calculation */&lt;BR /&gt;proc sql;&lt;BR /&gt;create table b3 as&lt;BR /&gt;select a.rf, b.*&lt;BR /&gt;from ff.factors_monthly as a, b2 as b&lt;BR /&gt;where a.year=b.year and a.month=b.month;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;/* Merge Option data with price data to identify moneyness */&lt;BR /&gt;&lt;BR /&gt;/* Discount Rate for Strike Price of options expiring at 'exdate' */&lt;BR /&gt;%let discount = (( 1 + b.rf) ** ( -(a.exdate-a.date)/30 )) ;&lt;BR /&gt;&lt;BR /&gt;/* Select option whose Strike Price PV is closest to current price */&lt;BR /&gt;proc sql;&lt;BR /&gt;create table _list as&lt;BR /&gt;select a.date, a.secid, a.price, a.exdate, a.strike , b.close,&lt;BR /&gt;a.optionid, a.strike*&amp;amp;discount - b.close as diff&lt;BR /&gt;from a2 as a, b3 as b&lt;BR /&gt;where a.date=b.date&lt;BR /&gt;group by a.date&lt;BR /&gt;having abs(diff)=min(abs(diff));&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;atm_otm=ATM %then %goto finalstep;&lt;BR /&gt;&lt;BR /&gt;/* Next Step is for OTM options Exclusively */&lt;BR /&gt;&lt;BR /&gt;%else %if &amp;amp;atm_otm=OTM %then %do;&lt;BR /&gt;%if &amp;amp;flag=C %then %let sign = &amp;lt; ;&lt;BR /&gt;%else %if &amp;amp;flag=P %then %let sign = &amp;gt; ;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;proc sql undo_policy=none;&lt;BR /&gt;create table _list2 as&lt;BR /&gt;select b.*, ((a.close + abs(a.diff)) - b.strike) as diff2&lt;BR /&gt;from _list(keep=date strike close diff) as a, a2 as b&lt;BR /&gt;where a.date=b.date and&lt;BR /&gt;( a.close + abs(a.diff) ) &amp;amp;sign b.strike /* Out the money OTM PUT sign is positive, OTM CALL sign is negative */&lt;BR /&gt;and&lt;BR /&gt;a.strike &amp;amp;sign b.strike&lt;BR /&gt;group by a.date&lt;BR /&gt;having abs(diff2)=min(abs(diff2)) ;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;/* Final Step bookmark */&lt;BR /&gt;%finalstep:&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;atm_otm=ATM %then %let inputfile= _list ;&lt;BR /&gt;%else %if &amp;amp;atm_otm=OTM %then %let inputfile= _list2 ;&lt;BR /&gt;&lt;BR /&gt;/* For selected options grab prices at the beg. of the next month */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table &amp;amp;outfile as&lt;BR /&gt;select intnx('month',a.date,0,'end') as DATE format yymmddn8.,&lt;BR /&gt;(b.price/a.price)-1 as Factor_Ret "Option-Based Factor" format percentn8.2,&lt;BR /&gt;"&amp;amp;flag" as flag, "&amp;amp;atm_otm" as money&lt;BR /&gt;from &amp;amp;inputfile as a, a1 as b&lt;BR /&gt;where a.optionid=b.optionid and intck('month',a.date,b.date)=1&lt;BR /&gt;group by a.date&lt;BR /&gt;having b.date=min(b.date)&lt;BR /&gt;order by a.date ;&lt;BR /&gt;quit;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Mar 2019 13:03:46 GMT</pubDate>
    <dc:creator>sasphd</dc:creator>
    <dc:date>2019-03-26T13:03:46Z</dc:date>
    <item>
      <title>Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro/m-p/546120#M74342</link>
      <description>&lt;P&gt;I want to know how to run this program. in other word the data file name and the variable that I must include in the data&lt;/P&gt;
&lt;P&gt;/***********************************************************************/&lt;BR /&gt;/* */&lt;BR /&gt;/* Program: Option-Based Factors */&lt;BR /&gt;/* Author : Luis Palacios, WRDS */&lt;BR /&gt;/* Date : 03/01/2010 */&lt;BR /&gt;/* Revised : 03/29/2010 */&lt;BR /&gt;/* Steps : */&lt;BR /&gt;/* - Get Daily option prices for all S&amp;amp;P500 options */&lt;BR /&gt;/* - S&amp;amp;P500 (SPX) secid in optionmetrics is 108105 */&lt;BR /&gt;/* - Filters applied on 1st trading day of month */&lt;BR /&gt;/* - Keep options expiring in the following month */&lt;BR /&gt;/* - Keep only options with available prices */&lt;BR /&gt;/* - Keep options with standard settlements */&lt;BR /&gt;/* */&lt;BR /&gt;/* Notes on SPX Options: */&lt;BR /&gt;/* - Expiration: Saturday Following the 3rd Friday of Expiration Month */&lt;BR /&gt;/* - Exercise Style: European exercisable on last bus day bef. exp. */&lt;BR /&gt;/* */&lt;BR /&gt;/* Example: %optionfactor(begyear=1996,endyear=2009, */&lt;BR /&gt;/* flag=C,atm_otm=OTM,outfile=myfinalOTM); */&lt;BR /&gt;/* ******************************************************************* */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro optionfactor&lt;BR /&gt;(begyear=1996,endyear=2012,flag=C,atm_otm=OTM,outfile=myfinalOTM,sp500_id=108105);&lt;BR /&gt;&lt;BR /&gt;data a1;&lt;BR /&gt;set %do i=&amp;amp;begyear %to &amp;amp;endyear; OPTIONM.OPPRCD&amp;amp;i&lt;BR /&gt;(keep = date secid exdate strike_price best_bid best_offer optionid&lt;BR /&gt;exdate ss_flag cp_flag where = (secid=&amp;amp;sp500_id)) %end; ;&lt;BR /&gt;month = month(date);&lt;BR /&gt;year = year(date) ;&lt;BR /&gt;/* Keep Options with Standard Settlment, i.e. 0 Special. Settl. Flag */&lt;BR /&gt;if ss_flag='0' and cp_flag="&amp;amp;flag" and best_bid&amp;gt;0 and best_offer&amp;gt;0;&lt;BR /&gt;/* Mid-Price */&lt;BR /&gt;price = (best_bid + best_offer)/2;&lt;BR /&gt;/* Strike Price Adjustment */&lt;BR /&gt;strike=strike_price/1000;&lt;BR /&gt;/* Standard SPX option expire Saturday (weekday=7)following the third Friday of the expiration month */&lt;BR /&gt;if weekday(exdate)=7; * it eliminates non standard-date options;&lt;BR /&gt;drop ss_flag cp_flag best_bid best_offer strike_price;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* Sort Dataset to Keep First Observation per Month */&lt;BR /&gt;proc sort data=a1 out=a1; by optionid year month date; run;&lt;BR /&gt;&lt;BR /&gt;/* Use Data from the First Trading Day of the Month */&lt;BR /&gt;/* Keep only Options that Expire in the Following Month */&lt;BR /&gt;data a2; set a1;&lt;BR /&gt;by optionid year month date;&lt;BR /&gt;if first.month;&lt;BR /&gt;if intck('month',date,exdate)=1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Get Price of the underlying index (S&amp;amp;P 500) */&lt;BR /&gt;data b1;&lt;BR /&gt;set %do i=&amp;amp;begyear %to &amp;amp;endyear %by 1;&lt;BR /&gt;optionm.secprd&amp;amp;i (where = (secid=&amp;amp;sp500_id)) %end; ;&lt;BR /&gt;month = month(date);&lt;BR /&gt;year = year(date);&lt;BR /&gt;/* CLOSE is closing price at the end of the day */&lt;BR /&gt;keep date year month close secid;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Sort Price Data */&lt;BR /&gt;proc sort data=b1 out=b1; by secid year month date; run;&lt;BR /&gt;&lt;BR /&gt;/* Keep data on first day of the month */&lt;BR /&gt;data b2; set b1;&lt;BR /&gt;by secid year month date;&lt;BR /&gt;if first.month;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/* Add Risk-Free Rate for Present Value Calculation */&lt;BR /&gt;proc sql;&lt;BR /&gt;create table b3 as&lt;BR /&gt;select a.rf, b.*&lt;BR /&gt;from ff.factors_monthly as a, b2 as b&lt;BR /&gt;where a.year=b.year and a.month=b.month;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;/* Merge Option data with price data to identify moneyness */&lt;BR /&gt;&lt;BR /&gt;/* Discount Rate for Strike Price of options expiring at 'exdate' */&lt;BR /&gt;%let discount = (( 1 + b.rf) ** ( -(a.exdate-a.date)/30 )) ;&lt;BR /&gt;&lt;BR /&gt;/* Select option whose Strike Price PV is closest to current price */&lt;BR /&gt;proc sql;&lt;BR /&gt;create table _list as&lt;BR /&gt;select a.date, a.secid, a.price, a.exdate, a.strike , b.close,&lt;BR /&gt;a.optionid, a.strike*&amp;amp;discount - b.close as diff&lt;BR /&gt;from a2 as a, b3 as b&lt;BR /&gt;where a.date=b.date&lt;BR /&gt;group by a.date&lt;BR /&gt;having abs(diff)=min(abs(diff));&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;atm_otm=ATM %then %goto finalstep;&lt;BR /&gt;&lt;BR /&gt;/* Next Step is for OTM options Exclusively */&lt;BR /&gt;&lt;BR /&gt;%else %if &amp;amp;atm_otm=OTM %then %do;&lt;BR /&gt;%if &amp;amp;flag=C %then %let sign = &amp;lt; ;&lt;BR /&gt;%else %if &amp;amp;flag=P %then %let sign = &amp;gt; ;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;proc sql undo_policy=none;&lt;BR /&gt;create table _list2 as&lt;BR /&gt;select b.*, ((a.close + abs(a.diff)) - b.strike) as diff2&lt;BR /&gt;from _list(keep=date strike close diff) as a, a2 as b&lt;BR /&gt;where a.date=b.date and&lt;BR /&gt;( a.close + abs(a.diff) ) &amp;amp;sign b.strike /* Out the money OTM PUT sign is positive, OTM CALL sign is negative */&lt;BR /&gt;and&lt;BR /&gt;a.strike &amp;amp;sign b.strike&lt;BR /&gt;group by a.date&lt;BR /&gt;having abs(diff2)=min(abs(diff2)) ;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;/* Final Step bookmark */&lt;BR /&gt;%finalstep:&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;atm_otm=ATM %then %let inputfile= _list ;&lt;BR /&gt;%else %if &amp;amp;atm_otm=OTM %then %let inputfile= _list2 ;&lt;BR /&gt;&lt;BR /&gt;/* For selected options grab prices at the beg. of the next month */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table &amp;amp;outfile as&lt;BR /&gt;select intnx('month',a.date,0,'end') as DATE format yymmddn8.,&lt;BR /&gt;(b.price/a.price)-1 as Factor_Ret "Option-Based Factor" format percentn8.2,&lt;BR /&gt;"&amp;amp;flag" as flag, "&amp;amp;atm_otm" as money&lt;BR /&gt;from &amp;amp;inputfile as a, a1 as b&lt;BR /&gt;where a.optionid=b.optionid and intck('month',a.date,b.date)=1&lt;BR /&gt;group by a.date&lt;BR /&gt;having b.date=min(b.date)&lt;BR /&gt;order by a.date ;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 13:03:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro/m-p/546120#M74342</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2019-03-26T13:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro/m-p/546124#M74343</link>
      <description>&lt;P&gt;You need a LIBNAME statement that defines a folder identified as OPTIONM:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libname OPTIONM 'path to folder';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WIthin that folder, you need SAS data sets covering the range of years that you would like to analyze:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OPRCD1996.sas7bdat&lt;/P&gt;
&lt;P&gt;OPRCD1997.sas7bdat&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;OPRCD2012.sas7bdat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The range of years needed can change, depending on the values supplied when calling the macro.&amp;nbsp; The default ranges from 1996 to 2012, but you can override that by specifying begyear= and endyear=.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 13:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro/m-p/546124#M74343</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-26T13:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro/m-p/546141#M74344</link>
      <description>&lt;P&gt;so I need a number of folder equal to the number of year that I have form 1996 to 2012. then 17&amp;nbsp;&lt;SPAN&gt;.sas7bdat???&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 13:28:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro/m-p/546141#M74344</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2019-03-26T13:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro/m-p/546152#M74345</link>
      <description>&lt;P&gt;You just need one folder.&amp;nbsp; The name of the folder doesn't matter, but you have to include it in the LIBNAME statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the SAS data sets need to reside in that folder.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 14:04:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro/m-p/546152#M74345</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-26T14:04:48Z</dc:date>
    </item>
  </channel>
</rss>

