<?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 How to use marco to change variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-marco-to-change-variable/m-p/68260#M14790</link>
    <description>This is my SAS macro to calculate american put or call by Cox-Ross-Rubinstein method:&lt;BR /&gt;
&lt;BR /&gt;
Macro to Calculate the call Intrinsic Option Value at Each NodeThis &lt;BR /&gt;
&lt;BR /&gt;
%macro cval(si,xi);&lt;BR /&gt;
(&amp;amp;si-ξ+abs(&amp;amp;si-ξ))/2&lt;BR /&gt;
%mend cval;&lt;BR /&gt;
* Macro to Calculate the callOption Price at Each Node;&lt;BR /&gt;
%macro c(ni,ss);&lt;BR /&gt;
%if ∋=&amp;amp;n %then &lt;BR /&gt;
%do;&lt;BR /&gt;
%cval (&amp;amp;ss,&amp;amp;x)&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
max(%cval(&amp;amp;ss,&amp;amp;x),((%c(∋+1,&amp;amp;ss*&amp;amp;u))*&amp;amp;p+(%c(∋+1,&amp;amp;ss*&amp;amp;d))*(1-&amp;amp;p))/&amp;amp;rq)&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend c; &lt;BR /&gt;
* Macro to Calculate the put Intrinsic Option Value at Each Node;&lt;BR /&gt;
%macro pval(si,xi);&lt;BR /&gt;
(&amp;amp;xi-&amp;amp;si+abs(&amp;amp;xi-&amp;amp;si))/2&lt;BR /&gt;
%mend pval;&lt;BR /&gt;
&lt;BR /&gt;
* Macro to Calculate the put Option Price at Each Node;&lt;BR /&gt;
%macro p(ni,ss);&lt;BR /&gt;
%if ∋=&amp;amp;n %then &lt;BR /&gt;
%do;&lt;BR /&gt;
%pval (&amp;amp;ss,&amp;amp;x)&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
max(%pval(&amp;amp;ss,&amp;amp;x),((%p(∋+1,&amp;amp;ss*&amp;amp;u))*&amp;amp;p+(%p(∋+1,&amp;amp;ss*&amp;amp;d))*(1-&amp;amp;p))/&amp;amp;rq)&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend p; &lt;BR /&gt;
&lt;BR /&gt;
data data1;&lt;BR /&gt;
input eq_price strike time opt_price intrate;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1108.48 995 0.041067762 0.8 0.01107094&lt;BR /&gt;
1122.22 995 0.032854209 0.35 0.011018561&lt;BR /&gt;
1123.67 995 0.030116359 0.3 0.01098864&lt;BR /&gt;
1126.33 995 0.027378508 0.2 0.01092533&lt;BR /&gt;
1131.92 995 0.024640657 0.2 0.010853256&lt;BR /&gt;
1121.86 995 0.021902806 0.175 0.0108289&lt;BR /&gt;
1127.23 995 0.013689254 0.075 0.010809861&lt;BR /&gt;
1121.22 995 0.010951403 0.1 0.010954211&lt;BR /&gt;
1122.22 1010 0.128678987 3.5 0.011561104&lt;BR /&gt;
1123.67 1010 0.125941136 3 0.011490423&lt;BR /&gt;
1126.33 1010 0.123203285 2.4 0.011465478&lt;BR /&gt;
1131.92 1010 0.120465435 2.4 0.011459139&lt;BR /&gt;
1121.86 1010 0.117727584 3.1 0.011313808&lt;BR /&gt;
1127.23 1010 0.109514031 2.45 0.011324488&lt;BR /&gt;
1121.22 1010 0.106776181 2.9 0.011172599&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
* Set the Option Variables and Call the Macros;&lt;BR /&gt;
data b;&lt;BR /&gt;
set data1;&lt;BR /&gt;
%let s=eq_price; * underlying security price;&lt;BR /&gt;
%let x=strike; * strike price;&lt;BR /&gt;
%let n=7; * nt = n = number of subperiods;&lt;BR /&gt;
%let t=time; * time to maturity, in years;&lt;BR /&gt;
%let h=&amp;amp;t/&amp;amp;n;* it=h=T/n= size of the sub-period;&lt;BR /&gt;
%let r=intrate; * r = continuously compounded risk free rate;&lt;BR /&gt;
%let q=0.0254; * dividend yield;&lt;BR /&gt;
%let sig=0.24; *implied Volatility;&lt;BR /&gt;
&lt;BR /&gt;
%let u =exp(&amp;amp;sig*sqrt(&amp;amp;h));&lt;BR /&gt;
%let d =exp(-&amp;amp;sig*sqrt(&amp;amp;h));&lt;BR /&gt;
%let rq=exp((&amp;amp;r-&amp;amp;q)*&amp;amp;h);&lt;BR /&gt;
%let p =(&amp;amp;rq-&amp;amp;d)/(&amp;amp;u-&amp;amp;d);&lt;BR /&gt;
&lt;BR /&gt;
p=%p(0,&amp;amp;s);&lt;BR /&gt;
c=%c(0,&amp;amp;s);&lt;BR /&gt;
output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
and the out put is&lt;BR /&gt;
&lt;BR /&gt;
The SAS System 11:42 Saturday, May 21, 2011 5&lt;BR /&gt;
&lt;BR /&gt;
Obs eq_price strike time opt_price intrate p c&lt;BR /&gt;
&lt;BR /&gt;
1 1108.48 995 0.04107 0.800 0.011071 0.17516 113.487&lt;BR /&gt;
2 1122.22 995 0.03285 0.350 0.011019 0.00000 127.220&lt;BR /&gt;
3 1123.67 995 0.03012 0.300 0.010989 0.00000 128.670&lt;BR /&gt;
4 1126.33 995 0.02738 0.200 0.010925 0.00000 131.330&lt;BR /&gt;
5 1131.92 995 0.02464 0.200 0.010853 0.00000 136.920&lt;BR /&gt;
6 1121.86 995 0.02190 0.175 0.010829 0.00000 126.860&lt;BR /&gt;
7 1127.23 995 0.01369 0.075 0.010810 0.00000 132.230&lt;BR /&gt;
8 1121.22 995 0.01095 0.100 0.010954 0.00000 126.220&lt;BR /&gt;
9 1122.22 1010 0.12868 3.500 0.011561 4.54713 115.75&lt;BR /&gt;
10 1123.67 1010 0.12594 3.000 0.011490 4.33255 117.00&lt;BR /&gt;
11 1126.33 1010 0.12320 2.400 0.011465 4.04350 119.39&lt;BR /&gt;
12 1131.92 1010 0.12047 2.400 0.011459 3.57726 124.54&lt;BR /&gt;
13 1121.86 1010 0.11773 3.100 0.011314 4.04854 114.96&lt;BR /&gt;
14 1127.23 1010 0.10951 2.450 0.011324 3.31856 119.67&lt;BR /&gt;
15 1121.22 1010 0.10678 2.900 0.011173 3.54189 113.90&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
But my macro use the sig which is only at 0.24,at this level, the answer p is not same to opt_price.&lt;BR /&gt;
I want to use the macro to change sig variable in my marco util the answer for p is same to opt_price.&lt;BR /&gt;
&lt;BR /&gt;
Please hlep me and give me a example to solve this problem? &lt;BR /&gt;
Thx!</description>
    <pubDate>Sun, 22 May 2011 07:40:02 GMT</pubDate>
    <dc:creator>nolonglove</dc:creator>
    <dc:date>2011-05-22T07:40:02Z</dc:date>
    <item>
      <title>How to use marco to change variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-marco-to-change-variable/m-p/68260#M14790</link>
      <description>This is my SAS macro to calculate american put or call by Cox-Ross-Rubinstein method:&lt;BR /&gt;
&lt;BR /&gt;
Macro to Calculate the call Intrinsic Option Value at Each NodeThis &lt;BR /&gt;
&lt;BR /&gt;
%macro cval(si,xi);&lt;BR /&gt;
(&amp;amp;si-ξ+abs(&amp;amp;si-ξ))/2&lt;BR /&gt;
%mend cval;&lt;BR /&gt;
* Macro to Calculate the callOption Price at Each Node;&lt;BR /&gt;
%macro c(ni,ss);&lt;BR /&gt;
%if ∋=&amp;amp;n %then &lt;BR /&gt;
%do;&lt;BR /&gt;
%cval (&amp;amp;ss,&amp;amp;x)&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
max(%cval(&amp;amp;ss,&amp;amp;x),((%c(∋+1,&amp;amp;ss*&amp;amp;u))*&amp;amp;p+(%c(∋+1,&amp;amp;ss*&amp;amp;d))*(1-&amp;amp;p))/&amp;amp;rq)&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend c; &lt;BR /&gt;
* Macro to Calculate the put Intrinsic Option Value at Each Node;&lt;BR /&gt;
%macro pval(si,xi);&lt;BR /&gt;
(&amp;amp;xi-&amp;amp;si+abs(&amp;amp;xi-&amp;amp;si))/2&lt;BR /&gt;
%mend pval;&lt;BR /&gt;
&lt;BR /&gt;
* Macro to Calculate the put Option Price at Each Node;&lt;BR /&gt;
%macro p(ni,ss);&lt;BR /&gt;
%if ∋=&amp;amp;n %then &lt;BR /&gt;
%do;&lt;BR /&gt;
%pval (&amp;amp;ss,&amp;amp;x)&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
max(%pval(&amp;amp;ss,&amp;amp;x),((%p(∋+1,&amp;amp;ss*&amp;amp;u))*&amp;amp;p+(%p(∋+1,&amp;amp;ss*&amp;amp;d))*(1-&amp;amp;p))/&amp;amp;rq)&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend p; &lt;BR /&gt;
&lt;BR /&gt;
data data1;&lt;BR /&gt;
input eq_price strike time opt_price intrate;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1108.48 995 0.041067762 0.8 0.01107094&lt;BR /&gt;
1122.22 995 0.032854209 0.35 0.011018561&lt;BR /&gt;
1123.67 995 0.030116359 0.3 0.01098864&lt;BR /&gt;
1126.33 995 0.027378508 0.2 0.01092533&lt;BR /&gt;
1131.92 995 0.024640657 0.2 0.010853256&lt;BR /&gt;
1121.86 995 0.021902806 0.175 0.0108289&lt;BR /&gt;
1127.23 995 0.013689254 0.075 0.010809861&lt;BR /&gt;
1121.22 995 0.010951403 0.1 0.010954211&lt;BR /&gt;
1122.22 1010 0.128678987 3.5 0.011561104&lt;BR /&gt;
1123.67 1010 0.125941136 3 0.011490423&lt;BR /&gt;
1126.33 1010 0.123203285 2.4 0.011465478&lt;BR /&gt;
1131.92 1010 0.120465435 2.4 0.011459139&lt;BR /&gt;
1121.86 1010 0.117727584 3.1 0.011313808&lt;BR /&gt;
1127.23 1010 0.109514031 2.45 0.011324488&lt;BR /&gt;
1121.22 1010 0.106776181 2.9 0.011172599&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
* Set the Option Variables and Call the Macros;&lt;BR /&gt;
data b;&lt;BR /&gt;
set data1;&lt;BR /&gt;
%let s=eq_price; * underlying security price;&lt;BR /&gt;
%let x=strike; * strike price;&lt;BR /&gt;
%let n=7; * nt = n = number of subperiods;&lt;BR /&gt;
%let t=time; * time to maturity, in years;&lt;BR /&gt;
%let h=&amp;amp;t/&amp;amp;n;* it=h=T/n= size of the sub-period;&lt;BR /&gt;
%let r=intrate; * r = continuously compounded risk free rate;&lt;BR /&gt;
%let q=0.0254; * dividend yield;&lt;BR /&gt;
%let sig=0.24; *implied Volatility;&lt;BR /&gt;
&lt;BR /&gt;
%let u =exp(&amp;amp;sig*sqrt(&amp;amp;h));&lt;BR /&gt;
%let d =exp(-&amp;amp;sig*sqrt(&amp;amp;h));&lt;BR /&gt;
%let rq=exp((&amp;amp;r-&amp;amp;q)*&amp;amp;h);&lt;BR /&gt;
%let p =(&amp;amp;rq-&amp;amp;d)/(&amp;amp;u-&amp;amp;d);&lt;BR /&gt;
&lt;BR /&gt;
p=%p(0,&amp;amp;s);&lt;BR /&gt;
c=%c(0,&amp;amp;s);&lt;BR /&gt;
output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
and the out put is&lt;BR /&gt;
&lt;BR /&gt;
The SAS System 11:42 Saturday, May 21, 2011 5&lt;BR /&gt;
&lt;BR /&gt;
Obs eq_price strike time opt_price intrate p c&lt;BR /&gt;
&lt;BR /&gt;
1 1108.48 995 0.04107 0.800 0.011071 0.17516 113.487&lt;BR /&gt;
2 1122.22 995 0.03285 0.350 0.011019 0.00000 127.220&lt;BR /&gt;
3 1123.67 995 0.03012 0.300 0.010989 0.00000 128.670&lt;BR /&gt;
4 1126.33 995 0.02738 0.200 0.010925 0.00000 131.330&lt;BR /&gt;
5 1131.92 995 0.02464 0.200 0.010853 0.00000 136.920&lt;BR /&gt;
6 1121.86 995 0.02190 0.175 0.010829 0.00000 126.860&lt;BR /&gt;
7 1127.23 995 0.01369 0.075 0.010810 0.00000 132.230&lt;BR /&gt;
8 1121.22 995 0.01095 0.100 0.010954 0.00000 126.220&lt;BR /&gt;
9 1122.22 1010 0.12868 3.500 0.011561 4.54713 115.75&lt;BR /&gt;
10 1123.67 1010 0.12594 3.000 0.011490 4.33255 117.00&lt;BR /&gt;
11 1126.33 1010 0.12320 2.400 0.011465 4.04350 119.39&lt;BR /&gt;
12 1131.92 1010 0.12047 2.400 0.011459 3.57726 124.54&lt;BR /&gt;
13 1121.86 1010 0.11773 3.100 0.011314 4.04854 114.96&lt;BR /&gt;
14 1127.23 1010 0.10951 2.450 0.011324 3.31856 119.67&lt;BR /&gt;
15 1121.22 1010 0.10678 2.900 0.011173 3.54189 113.90&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
But my macro use the sig which is only at 0.24,at this level, the answer p is not same to opt_price.&lt;BR /&gt;
I want to use the macro to change sig variable in my marco util the answer for p is same to opt_price.&lt;BR /&gt;
&lt;BR /&gt;
Please hlep me and give me a example to solve this problem? &lt;BR /&gt;
Thx!</description>
      <pubDate>Sun, 22 May 2011 07:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-marco-to-change-variable/m-p/68260#M14790</guid>
      <dc:creator>nolonglove</dc:creator>
      <dc:date>2011-05-22T07:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use marco to change variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-marco-to-change-variable/m-p/68261#M14791</link>
      <description>I guess you need to write some sort of a %DO %UNTIL loop for this?</description>
      <pubDate>Thu, 02 Jun 2011 14:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-marco-to-change-variable/m-p/68261#M14791</guid>
      <dc:creator>PatrickG</dc:creator>
      <dc:date>2011-06-02T14:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use marco to change variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-marco-to-change-variable/m-p/68262#M14792</link>
      <description>You need to review the difference between the routine CALL SYMPUTX and the use of %LET in a DATA step.  It is not possible to assign DATA step variable's value to a macro variable using a %LET - the DATA step routine SYMUTX is used instead.  It is very important to understand why.&lt;BR /&gt;
&lt;BR /&gt;
in your program (snippet shown here).&lt;BR /&gt;
[pre]&lt;BR /&gt;
data b;&lt;BR /&gt;
set data1;&lt;BR /&gt;
%let s=eq_price; * underlying security price;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
the macro variable &amp;amp;S will contain the letters e-q-_-p-r-i-c-e, not the variable and not the value of the variable.  This means that the %IF in the macro %P will always be false.</description>
      <pubDate>Sun, 05 Jun 2011 06:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-marco-to-change-variable/m-p/68262#M14792</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2011-06-05T06:08:53Z</dc:date>
    </item>
  </channel>
</rss>

