Learn / Advanced ALM

SAS-to-Python Model Parity

Insurers modernize legacy SAS liability models onto Python and a cloud runtime. Copying syntax is not proof. Methodology, assumptions, missing-value rules, and the business total have to survive the move. This lab runs two independent browser implementations on a synthetic book. It does not execute SAS, and it is not a production model.

01

Why model parity matters

A translation can look right line by line and still miss the book. Numeric precision, missing values, data types, date logic, rounding, sort order, and aggregation each move the total. Actuarial, finance, IT, model validation, and the business owner all have to read the same evidence.

Lifecycle: Legacy SAS Model โ†’ Methodology Analysis โ†’ Python Translation โ†’ Parallel Execution โ†’ Reconciliation โ†’ Validation โ†’ Production Release.

Think of two clerks adding the same stack of IOUs. One uses the old worksheet. The other rewrote the worksheet on a new pad. If they disagree by $12 million, you do not ship. You find which line they treated differently.

02

Illustrative SAS and the Python translation

The snippets below are the teaching identities. They are not a valuation system and not a SAS session.

Illustrative SAS logic โ€” not executed
data liability_output;
  set policy_input;
  net_cash_flow = annual_premium - annual_withdrawal;
  survival_prob = (1 - mortality_rate) ** projection_year;
  discount_factor = 1 / (1 + discount_rate) ** projection_year;
  projected_cash_flow = net_cash_flow * survival_prob;
  present_value = projected_cash_flow * discount_factor;
run;

proc means data=liability_output sum;
  var present_value;
run;

A row-wise DATA step, then a SUM. The browser runs a SAS-reference implementation of these identities. It does not run SAS.

Python translation โ€” separate map/reduce
df["net_cash_flow"] = (
  df["annual_premium"] - df["annual_withdrawal"]
)
df["survival_prob"] = (
  (1 - df["mortality_rate"]) ** df["projection_year"]
)
df["discount_factor"] = (
  1 / (1 + df["discount_rate"]) ** df["projection_year"]
)
df["projected_cash_flow"] = (
  df["net_cash_flow"] * df["survival_prob"]
)
df["present_value"] = (
  df["projected_cash_flow"] * df["discount_factor"]
)
total_liability = df["present_value"].sum()

Same identities, different walk. Precision, missing values, rounding, and aggregation are where translations usually drift.

03

Parallel run and reconciliation

Teaching lab

SAS-to-Python Model Parity

Two hundred synthetic policies. The left total is a SAS-reference walk. The right total is a separate Python-style map/reduce. The browser does not execute SAS. Records are educational, not a policy extract.

Expected classroom outcome. Totals match within tolerance. Both engines drop the same incomplete rows.

Effective gate is the larger of this dollar floor and 0.05% of the SAS-reference total ($93,362). Percentage uses the SAS-reference total as the denominator.

SAS-reference liability
$186,724,696

192 complete rows. 8 incomplete rows are listed below.

Python liability
$186,724,696

192 rows in the translated sum.

Absolute difference
$0

Python minus SAS-reference. Full precision, then displayed.

Percentage difference
0.000%

Denominator is the SAS-reference total.

Tolerance
$93,362

Floor $1,000 or 0.05% of SAS.

Status
Pass

Inside tolerance.

SAS-reference versus Python totalsSAS-reference $186,724,696. Python $186,724,696.Book totalsSAS-refPython

Both implementations used the same inputs and the same one-step present-value identities. Absolute difference is 0.00.

Guided challenge

You converted an actuarial liability model from SAS to Python. The two implementations differ by about $12 million. Identify the cause, correct the implementation, and achieve model parity.

The seeded book is sized so a 4.5% vs 4.0% discount defect lands between $11,500,000 and $12,500,000. Current challenge gap $12,000,000.

Data quality reconciliation

Parity is not only a dollar compare. Both engines see the same seeded extract, the same assumption version, and the same as-of date. Incomplete rows are listed so an exclusion cannot hide inside the total.

Input rows
200

Unique ids 200.

Valid / invalid
192 / 8

SAS includes 192. Python includes 192.

Duplicate policy IDs
None

A duplicate id would double-count one contract.

Assumption version
parity-one-step-v1

Shared classroom methodology label.

As-of date
2026-10-31

Seed 20261031. Teaching date, not a valuation date.

Missing-value rule
Same on both

Baseline and this defect drop the same incomplete rows on both implementations.

Missing required fields by name
Required fieldMissing or invalid
mortalityRate4
discountRate4
annualPremium0
annualWithdrawal0
projectionYear0

Excluded records

8 incomplete policies are outside the official totals. Potential impact uses a documented teaching fill (mortality 0%, discount 4.00%) and is not a production imputation. Combined potential impact $9,469,432.

Excluded synthetic policies and why each was dropped
PolicyMissing fieldsReasonPotential PVKept by
SYN-001mortalityRateMissing or invalid required field: mortalityRate.$1,587,019Neither
SYN-026discountRateMissing or invalid required field: discountRate.$265,325Neither
SYN-051mortalityRateMissing or invalid required field: mortalityRate.$1,352,401Neither
SYN-076discountRateMissing or invalid required field: discountRate.$1,113,087Neither
SYN-101mortalityRateMissing or invalid required field: mortalityRate.$1,271,614Neither
SYN-126discountRateMissing or invalid required field: discountRate.$1,571,911Neither
SYN-151mortalityRateMissing or invalid required field: mortalityRate.$1,364,927Neither
SYN-176discountRateMissing or invalid required field: discountRate.$943,149Neither

Policy-level reconciliation

Sorted by absolute dollar difference among rows that produced a present value. Incomplete policies are in the exclusions table above. Select a row to read the intermediate steps. Color is not the only status signal.

Policy present values from the SAS-reference and Python implementations.
PolicySAS-referencePythonDifferenceStatus
$1,350,975$1,350,975$0Pass
$1,018,644$1,018,644$0Pass
$1,032,142$1,032,142$0Pass
$618,404$618,404$0Pass
$1,528,145$1,528,145$0Pass
$1,740,021$1,740,021$0Pass
$878,401$878,401$0Pass
$1,050,757$1,050,757$0Pass
$1,055,873$1,055,873$0Pass
$811,538$811,538$0Pass
$1,107,124$1,107,124$0Pass
$1,259,613$1,259,613$0Pass

Steps for SYN-002

SAS-reference: net $2,574,122, survival 0.807951, discount 0.649581, PV $1,350,975. Rate 4.00%, year 11.

Python: net $2,574,122, survival 0.807951, discount 0.649581, PV $1,350,975. Rate 4.00%, year 11.

Teaching only

Release readiness

A classroom checklist, not a real approval workflow. Each item now has an evidence reference plus owner, reviewer, and date fields so the exercise looks more like an enterprise packet. Ticking a box here does not ship a model.

Readiness 5 of 12

  • On โ€” Input data validated

    Synthetic book is labeled and seeded.

    data sign-off fields

  • On โ€” Assumptions verified

    Discount, mortality, and year are on each complete row.

    assumptions sign-off fields

  • On โ€” Unit tests passed

    parityMath.test.ts covers identities, defects, exclusions, and data quality.

    unit sign-off fields

  • On โ€” Regression tests passed

    On when the Python path has no injected defect.

    regression sign-off fields

  • On โ€” SAS/Python reconciliation completed

    On when the book difference is inside tolerance.

    reconcile sign-off fields

  • source sign-off fields

  • methodology sign-off fields

  • tolerance sign-off fields

  • independent sign-off fields

  • owner sign-off fields

  • deploy sign-off fields

  • rollback sign-off fields

04

Behind the scenes

  1. Build a seeded book of 200 synthetic policies in the browser.
  2. Run the SAS-reference walk and the Python map/reduce on the same rows.
  3. Compare totals, each policy, and data quality (counts, missing fields, duplicates, version, as-of).
  4. List incomplete rows with the missing fields and a teaching-fill potential impact.
  5. Inject one Python defect at a time. The SAS-reference total stays put.
  6. Read the largest variances and the intermediate steps. Reset to restore parity.

05

Limitations

One-step present value, not a multi-year decrement study. Period-by-period cash flows, lapse, annuity guarantees, and a discount curve are a later enhancement, not a missing piece of this lab. No stochastic scenarios, no statutory or GAAP books, no real policy data, and no SAS runtime. Production parity needs approved methodology, representative data, independent validation, documented tolerances, and a human owner.

Related pages: Advanced ALM hub ยท Actuarial liability modeling ยท Quantitative finance ยท Economic risk and GAAP.

Trades | Learn. Practice. Analyze. Improve.