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.
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.
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
- Python liability
- $186,724,696
- Absolute difference
- $0
- Percentage difference
- 0.000%
- Tolerance
- $93,362
- Status
- Pass
192 complete rows. 8 incomplete rows are listed below.
192 rows in the translated sum.
Python minus SAS-reference. Full precision, then displayed.
Denominator is the SAS-reference total.
Floor $1,000 or 0.05% of SAS.
Inside tolerance.
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
- Valid / invalid
- 192 / 8
- Duplicate policy IDs
- None
- Assumption version
- parity-one-step-v1
- As-of date
- 2026-10-31
- Missing-value rule
- Same on both
Unique ids 200.
SAS includes 192. Python includes 192.
A duplicate id would double-count one contract.
Shared classroom methodology label.
Seed 20261031. Teaching date, not a valuation date.
Baseline and this defect drop the same incomplete rows on both implementations.
| Required field | Missing or invalid |
|---|---|
| mortalityRate | 4 |
| discountRate | 4 |
| annualPremium | 0 |
| annualWithdrawal | 0 |
| projectionYear | 0 |
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.
| Policy | Missing fields | Reason | Potential PV | Kept by |
|---|---|---|---|---|
| SYN-001 | mortalityRate | Missing or invalid required field: mortalityRate. | $1,587,019 | Neither |
| SYN-026 | discountRate | Missing or invalid required field: discountRate. | $265,325 | Neither |
| SYN-051 | mortalityRate | Missing or invalid required field: mortalityRate. | $1,352,401 | Neither |
| SYN-076 | discountRate | Missing or invalid required field: discountRate. | $1,113,087 | Neither |
| SYN-101 | mortalityRate | Missing or invalid required field: mortalityRate. | $1,271,614 | Neither |
| SYN-126 | discountRate | Missing or invalid required field: discountRate. | $1,571,911 | Neither |
| SYN-151 | mortalityRate | Missing or invalid required field: mortalityRate. | $1,364,927 | Neither |
| SYN-176 | discountRate | Missing or invalid required field: discountRate. | $943,149 | Neither |
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 | SAS-reference | Python | Difference | Status |
|---|---|---|---|---|
| $1,350,975 | $1,350,975 | $0 | Pass | |
| $1,018,644 | $1,018,644 | $0 | Pass | |
| $1,032,142 | $1,032,142 | $0 | Pass | |
| $618,404 | $618,404 | $0 | Pass | |
| $1,528,145 | $1,528,145 | $0 | Pass | |
| $1,740,021 | $1,740,021 | $0 | Pass | |
| $878,401 | $878,401 | $0 | Pass | |
| $1,050,757 | $1,050,757 | $0 | Pass | |
| $1,055,873 | $1,055,873 | $0 | Pass | |
| $811,538 | $811,538 | $0 | Pass | |
| $1,107,124 | $1,107,124 | $0 | Pass | |
| $1,259,613 | $1,259,613 | $0 | Pass |
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
- Build a seeded book of 200 synthetic policies in the browser.
- Run the SAS-reference walk and the Python map/reduce on the same rows.
- Compare totals, each policy, and data quality (counts, missing fields, duplicates, version, as-of).
- List incomplete rows with the missing fields and a teaching-fill potential impact.
- Inject one Python defect at a time. The SAS-reference total stays put.
- 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.
