<?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: Excel Solver to SAS using PROC FCMP in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/982344#M379304</link>
    <description>&lt;P&gt;/* Solution Using PROC IML */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* 1. Create the input dataset (same as original) */&lt;BR /&gt;data have;&lt;BR /&gt;input NCp PDt0;&lt;BR /&gt;format PDt0 percent8.2;&lt;BR /&gt;cards;&lt;BR /&gt;10 0.0001&lt;BR /&gt;14 0.0005&lt;BR /&gt;18 0.01&lt;BR /&gt;24 0.02&lt;BR /&gt;13 0.05&lt;BR /&gt;5 0.12&lt;BR /&gt;2 0.25&lt;BR /&gt;1 0.40&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* 2. Solve using PROC IML */&lt;BR /&gt;proc iml;&lt;BR /&gt;/* --- A. Read Data into Matrix Vectors --- */&lt;BR /&gt;use have;&lt;BR /&gt;read all var {NCp PDt0};&lt;BR /&gt;close have;&lt;/P&gt;&lt;P&gt;/* --- B. Define Constants --- */&lt;BR /&gt;targetPD = 0.04;&lt;/P&gt;&lt;P&gt;/* --- C. Define the Function to Solve --- */&lt;BR /&gt;/* We want to find alpha such that:&lt;BR /&gt;(Weighted Avg PD based on alpha) - TargetPD = 0 */&lt;BR /&gt;start DiffFunction(x) global(NCp, PDt0, targetPD);&lt;BR /&gt;/* Note: # is element-wise multiplication, ## is element-wise power */&lt;BR /&gt;weighted_sum = sum(NCp # (PDt0##x));&lt;BR /&gt;total_weight = sum(NCp);&lt;BR /&gt;&lt;BR /&gt;calculated_PD = weighted_sum / total_weight;&lt;BR /&gt;&lt;BR /&gt;/* Return the difference (residual) */&lt;BR /&gt;return (calculated_PD - targetPD);&lt;BR /&gt;finish;&lt;/P&gt;&lt;P&gt;/* --- D. Find the Root (Alpha) --- */&lt;BR /&gt;/* Search for alpha in the range [0, 5]. Adjust this interval if needed. */&lt;BR /&gt;intervals = {0 5};&lt;BR /&gt;&lt;BR /&gt;/* FROOT finds the zero of the function defined in "DiffFunction" */&lt;BR /&gt;alpha = froot("DiffFunction", intervals);&lt;/P&gt;&lt;P&gt;/* --- E. Output Results --- */&lt;BR /&gt;print alpha targetPD;&lt;/P&gt;&lt;P&gt;/* Save to a dataset */&lt;BR /&gt;create want var {targetPD alpha};&lt;BR /&gt;append;&lt;BR /&gt;close want;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;/* Check results */&lt;BR /&gt;proc print data=want;&lt;BR /&gt;format alpha best12. targetPD percent8.2;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jan 2026 00:43:34 GMT</pubDate>
    <dc:creator>raphaelchaves</dc:creator>
    <dc:date>2026-01-23T00:43:34Z</dc:date>
    <item>
      <title>Excel Solver to SAS using PROC FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833077#M329313</link>
      <description>&lt;P&gt;Hello All&lt;/P&gt;&lt;P&gt;I'm trying to replicate in SAS a calculation created using Excel Solver.&lt;/P&gt;&lt;P&gt;The&amp;nbsp;procedure is an iterative solver that adjust the variable Target PD (Probability of Default) by changing the values of the alpha).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jorge_Ribeiro_1-1663061422748.png" style="width: 626px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75178i4FBCC401DDB92E21/image-dimensions/626x385?v=v2" width="626" height="385" role="button" title="Jorge_Ribeiro_1-1663061422748.png" alt="Jorge_Ribeiro_1-1663061422748.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I included the excel file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The input are : Number of counterparties and Probabilities (PD)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 09:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833077#M329313</guid>
      <dc:creator>Jorge_Ribeiro</dc:creator>
      <dc:date>2022-09-13T09:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Excel Solver to SAS using PROC FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833084#M329314</link>
      <description>&lt;P&gt;What arguments should the function / routine accept? What should it return?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 10:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833084#M329314</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-13T10:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Excel Solver to SAS using PROC FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833086#M329315</link>
      <description>&lt;P&gt;The alpha indicated in the solver, look :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jorge_Ribeiro_0-1663065032919.png" style="width: 653px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75182i3C389BFC06D103C9/image-dimensions/653x695?v=v2" width="653" height="695" role="button" title="Jorge_Ribeiro_0-1663065032919.png" alt="Jorge_Ribeiro_0-1663065032919.png" /&gt;&lt;/span&gt;.&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 10:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833086#M329315</guid>
      <dc:creator>Jorge_Ribeiro</dc:creator>
      <dc:date>2022-09-13T10:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Excel Solver to SAS using PROC FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833090#M329318</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/433585"&gt;@Jorge_Ribeiro&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Define functions
   JR   to compute PD at t=1
   OPTA to compute alpha for a given target PD
*/

proc fcmp outlib=work.funcs.test;
function JR(NCp[*], PDt0_[*], alpha);
  do i=1 to dim(NCp);
    s + NCp[i]*PDt0_[i]**alpha;
    w + NCp[i];
  end;
  return(s/w);
endfunc;
function opta(NCp[*], PDt0_[*], targetPD);
  a=solve("JR", {.}, targetPD, NCp, PDt0_, .);
  return(a);
endfunc;
run;

/* Make functions available */

options cmplib=work.funcs;

/* Create input dataset for demonstration */

data have;
input NCp PDt0;
retain targetPD 0.04;
format PDt0 targetPD percent8.2;
cards;
10 0.0001
14 0.0005
18 0.01
24 0.02
13 0.05
 5 0.12
 2 0.25
 1 0.40
;

/* Apply function OPTA to dataset HAVE */

data want(keep=targetPD alpha);
array _N[99] _temporary_;
array _P[99] _temporary_;
set have end=last;
_N[_n_]=NCp;
_P[_n_]=PDt0;
if last;
alpha=opta(_N, _P, targetPD);
run;

proc print data=want;
format alpha best12.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you change the 0.04 in the RETAIN statement for &lt;FONT face="courier new,courier"&gt;targetPD&lt;/FONT&gt; to 0.05, you'll get&amp;nbsp;&lt;FONT face="courier new,courier"&gt;alpha=0.834153&lt;/FONT&gt;... (with a minor difference to the Excel value) as the result. If needed, an "options array" could be added to function OPTA so that you could specify an initial value, convergence criteria, etc. (see documentation of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p1xoknqns865t7n1wehj6xarwhdb.htm" target="_blank" rel="noopener"&gt;SOLVE function&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 11:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833090#M329318</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-09-13T11:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Excel Solver to SAS using PROC FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833093#M329320</link>
      <description>&lt;P&gt;Your solution is brilliant.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Jorge Ribeiro.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 12:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833093#M329320</guid>
      <dc:creator>Jorge_Ribeiro</dc:creator>
      <dc:date>2022-09-13T12:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Excel Solver to SAS using PROC FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833119#M329331</link>
      <description>&lt;P&gt;I think the best tool for this question is SAS/IML .&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt; would love to use IML to solve it.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 13:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/833119#M329331</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-13T13:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Excel Solver to SAS using PROC FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/982344#M379304</link>
      <description>&lt;P&gt;/* Solution Using PROC IML */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* 1. Create the input dataset (same as original) */&lt;BR /&gt;data have;&lt;BR /&gt;input NCp PDt0;&lt;BR /&gt;format PDt0 percent8.2;&lt;BR /&gt;cards;&lt;BR /&gt;10 0.0001&lt;BR /&gt;14 0.0005&lt;BR /&gt;18 0.01&lt;BR /&gt;24 0.02&lt;BR /&gt;13 0.05&lt;BR /&gt;5 0.12&lt;BR /&gt;2 0.25&lt;BR /&gt;1 0.40&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* 2. Solve using PROC IML */&lt;BR /&gt;proc iml;&lt;BR /&gt;/* --- A. Read Data into Matrix Vectors --- */&lt;BR /&gt;use have;&lt;BR /&gt;read all var {NCp PDt0};&lt;BR /&gt;close have;&lt;/P&gt;&lt;P&gt;/* --- B. Define Constants --- */&lt;BR /&gt;targetPD = 0.04;&lt;/P&gt;&lt;P&gt;/* --- C. Define the Function to Solve --- */&lt;BR /&gt;/* We want to find alpha such that:&lt;BR /&gt;(Weighted Avg PD based on alpha) - TargetPD = 0 */&lt;BR /&gt;start DiffFunction(x) global(NCp, PDt0, targetPD);&lt;BR /&gt;/* Note: # is element-wise multiplication, ## is element-wise power */&lt;BR /&gt;weighted_sum = sum(NCp # (PDt0##x));&lt;BR /&gt;total_weight = sum(NCp);&lt;BR /&gt;&lt;BR /&gt;calculated_PD = weighted_sum / total_weight;&lt;BR /&gt;&lt;BR /&gt;/* Return the difference (residual) */&lt;BR /&gt;return (calculated_PD - targetPD);&lt;BR /&gt;finish;&lt;/P&gt;&lt;P&gt;/* --- D. Find the Root (Alpha) --- */&lt;BR /&gt;/* Search for alpha in the range [0, 5]. Adjust this interval if needed. */&lt;BR /&gt;intervals = {0 5};&lt;BR /&gt;&lt;BR /&gt;/* FROOT finds the zero of the function defined in "DiffFunction" */&lt;BR /&gt;alpha = froot("DiffFunction", intervals);&lt;/P&gt;&lt;P&gt;/* --- E. Output Results --- */&lt;BR /&gt;print alpha targetPD;&lt;/P&gt;&lt;P&gt;/* Save to a dataset */&lt;BR /&gt;create want var {targetPD alpha};&lt;BR /&gt;append;&lt;BR /&gt;close want;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;/* Check results */&lt;BR /&gt;proc print data=want;&lt;BR /&gt;format alpha best12. targetPD percent8.2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2026 00:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excel-Solver-to-SAS-using-PROC-FCMP/m-p/982344#M379304</guid>
      <dc:creator>raphaelchaves</dc:creator>
      <dc:date>2026-01-23T00:43:34Z</dc:date>
    </item>
  </channel>
</rss>

