I use proc surveyreg to conduct regression analyses, but I have several versions of independent variables for robustness. To simplify, I would like to use the dataset, CARs, in sashelp library. Let's assume that &indep1 - &indep3 are variables of interest.
%let indep1= Invoice; %let indep2= EngineSize; %let indep3= Cylinders; %let controltemp= weight wheelbase length; proc surveyreg data= sashelp.cars; model MSRP= &indep1 &controltemp; run; proc surveyreg data= sashelp.cars; model MSRP= &indep2 &controltemp; run; proc surveyreg data= sashelp.cars; model MSRP= &indep3 &controltemp; run;
After running the regression, I would like to see three regression results together to assess their robustness. Put differently, I would like to make tables as follows:
model 1 model 2 model 3
Indep1 coff
Indep2 coff
Indep3 coff
weight coff coff coff
wheelbase coff coff coff
length coff coff coff
I know it's very easy in stata, but how can I make the above table easily in SAS? One way I can think of is to get them merged using proc sql after estimating each model, which doesn't sound convenient. It turned out that this way requires more lines than I expected it would. I reasonably believe there is a better, simpler way for this. Thanks!
Create output data sets of the desired elements from each surveyreg step and the append the results together.
With Surveyreg you will likely need to use ODS OUTPUT statements to create the desired sets.
Something like:
%let indep1= Invoice; %let indep2= EngineSize; %let indep3= Cylinders; %let controltemp= weight wheelbase length; proc surveyreg data= sashelp.cars; model MSRP= &indep1 &controltemp; ods output parameterestimates=model1; run; proc surveyreg data= sashelp.cars; model MSRP= &indep2 &controltemp; ods output parameterestimates=model2; run; proc surveyreg data= sashelp.cars; model MSRP= &indep3 &controltemp; ods output parameterestimates=model3; run; data work.allmodels; set model1 model2 model3 indsname=dsn; model= scan(dsn,2,'.'); run;
I'm not quite sure what sort of "table" you wanted for the final. You could either write reports from that data set or possibly transpose if for other comparisons. Since this basic example has 5 "coefficients" I'm not sure what your "table" actually wants.
Note that the Parameter length can vary based on your data and the combining step has a possibility of truncating the name if the later models have variable names that are longer than those in the earlier models. That would require a Length statement prior to the SET in the combining data step to set a default length for the for the variable to contain the longest value.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.