This code fits a linear regression model to the data in the dataframe df, using a stepwise regression on the columns 'x1', 'x2', ..., 'x10' as the independent variables and the column 'y' as the dependent variable. It then prints a summary of the regression results and the python code additionally saves the estimates and p-values of the regression coefficients to a CSV file.

SAS

proc reg data=Simulate outest=Estimates;
model y=x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 / selection=adjrsq sse aic adjrsq;
* Output Predicted and Residual;
output out=out p=p r=r;
run;
quit;

Python

import pandas as pd
import statsmodels.api as sm
from statsmodels.regression.linear_model import stepwise_fit
# Steps 1-3 below aren't needed if you use the simulated data
################################################
#Step1 Load the data into a pandas dataframe
df = pd.read_csv('data.csv')
#Step2 Set the dependent variable
y = df['y']
#Step3 Set the independent variables
X = df[['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9', 'x10']]
###################################################

# Add a constant to the independent variables
X = sm.add_constant(X)

# Fit the stepwise regression model
model = stepwise_fit(X, y)

# Print the regression summary
print(model.summary())

# Extract the regression coefficients and p-values
estimates = model.params
p_values = model.pvalues

# Create a dataframe to store the estimates and p-values
estimates_df = pd.DataFrame({'estimate': estimates, 'p_value': p_values})

# Save the estimates and p-values to a CSV file
estimates_df.to_csv