This may be a simple answer but I'm not quite sure how to do it.
I am running proc reg on my data set using by variable called "Deal_id" there are about 640 deal_id points and 200 points for each deal id.
I've been using proc reg and running it no problem to find the different slopes and intercepts using the code below:
proc reg data =temp1;
model ret = mret;
by deal_id;
run;
What I'm trying to do after to have a table created that will show deal_id then each respect slope and intercept and standard error for the 640 cases from the regression run. I can't figure out how to pull out these three variables into a new table. Maybe there is another PROC that makes this simpler?
@nmlynar13 wrote:
This may be a simple answer but I'm not quite sure how to do it.
I am running proc reg on my data set using by variable called "Deal_id" there are about 640 deal_id points and 200 points for each deal id.
I've been using proc reg and running it no problem to find the different slopes and intercepts using the code below:
proc reg data =temp1;
model ret = mret;
by deal_id;
run;
What I'm trying to do after to have a table created that will show deal_id then each respect slope and intercept and standard error for the 640 cases from the regression run. I can't figure out how to pull out these three variables into a new table. Maybe there is another PROC that makes this simpler?
SAS has a method that will place the data from any of the tables in the results into a data set called ODS OUTPUT. The sytnax is: ods output <procedure table name>= <name of data set you want>. The "trick" is knowing which table name(s) you want. The documentation for most procedures will have section of ODS Tables in the Detail tab.
Or you can use the ODS Trace command to generate a list. Example follows. (Note: do this with a small data set and only one or two by groups as this has the potential to generate a lot to log information.
Consider (you should be able to run this data since the data set is provided by SAS)
proc sort data=sashelp.class out=work.class; by sex; run; ods trace on; proc reg data=work.class; by sex; model height=age; run; quit; ods trace off;
This generates in the LOG:
Output Added: ------------- Name: NObs Label: Number of Observations Template: Stat.Reg.NObs Path: Reg.ByGroup1.MODEL1.Fit.Height.NObs ------------- Output Added: ------------- Name: ANOVA Label: Analysis of Variance Template: Stat.REG.ANOVA Path: Reg.ByGroup1.MODEL1.Fit.Height.ANOVA ------------- Output Added: ------------- Name: FitStatistics Label: Fit Statistics Template: Stat.REG.FitStatistics Path: Reg.ByGroup1.MODEL1.Fit.Height.FitStatistics ------------- Output Added: ------------- Name: ParameterEstimates Label: Parameter Estimates Template: Stat.REG.ParameterEstimates Path: Reg.ByGroup1.MODEL1.Fit.Height.ParameterEstimates ------------- NOTE: The above message was for the following BY group: Sex=F Output Added: ------------- Name: NObs Label: Number of Observations Template: Stat.Reg.NObs Path: Reg.ByGroup2.MODEL1.Fit.Height.NObs ------------- Output Added: ------------- Name: ANOVA Label: Analysis of Variance Template: Stat.REG.ANOVA Path: Reg.ByGroup2.MODEL1.Fit.Height.ANOVA ------------- Output Added: ------------- Name: FitStatistics Label: Fit Statistics Template: Stat.REG.FitStatistics Path: Reg.ByGroup2.MODEL1.Fit.Height.FitStatistics ------------- Output Added: ------------- Name: ParameterEstimates Label: Parameter Estimates Template: Stat.REG.ParameterEstimates Path: Reg.ByGroup2.MODEL1.Fit.Height.ParameterEstimates ------------- NOTE: The above message was for the following BY group: Sex=M NOTE: Interactivity disabled with BY processing. NOTE: PROCEDURE REG used (Total process time): real time 0.55 seconds cpu time 0.31 seconds
The important part for your question is the NAME for each. Notice that the tables in the log appear in the order they do in the results window. Then you modify the code of the procedure as:
proc reg data=work.class; by sex; model height=age; ods output parameterestimates=work.myestimates; run; quit;
to send the parameterestimates table to a data set work.myestimates.
Also if you read the documentation at https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=statug&docsetTarget=statu...
you will see that Proc Reg has an option OUTEST= that creates a data set with parameter estimates. You could add to the PROC statement OUTEST=work.myparmestimates or whatever.
You may ask why I showed the longer form first. Not all procedures have output data set options (Surveyreg for example) and there are many different tables that procedures can generate. Those that do have some output datasets do not always have one that sends what you may want to a data set. But the ODS OUTPUT will work.
@nmlynar13 wrote:
This may be a simple answer but I'm not quite sure how to do it.
I am running proc reg on my data set using by variable called "Deal_id" there are about 640 deal_id points and 200 points for each deal id.
I've been using proc reg and running it no problem to find the different slopes and intercepts using the code below:
proc reg data =temp1;
model ret = mret;
by deal_id;
run;
What I'm trying to do after to have a table created that will show deal_id then each respect slope and intercept and standard error for the 640 cases from the regression run. I can't figure out how to pull out these three variables into a new table. Maybe there is another PROC that makes this simpler?
SAS has a method that will place the data from any of the tables in the results into a data set called ODS OUTPUT. The sytnax is: ods output <procedure table name>= <name of data set you want>. The "trick" is knowing which table name(s) you want. The documentation for most procedures will have section of ODS Tables in the Detail tab.
Or you can use the ODS Trace command to generate a list. Example follows. (Note: do this with a small data set and only one or two by groups as this has the potential to generate a lot to log information.
Consider (you should be able to run this data since the data set is provided by SAS)
proc sort data=sashelp.class out=work.class; by sex; run; ods trace on; proc reg data=work.class; by sex; model height=age; run; quit; ods trace off;
This generates in the LOG:
Output Added: ------------- Name: NObs Label: Number of Observations Template: Stat.Reg.NObs Path: Reg.ByGroup1.MODEL1.Fit.Height.NObs ------------- Output Added: ------------- Name: ANOVA Label: Analysis of Variance Template: Stat.REG.ANOVA Path: Reg.ByGroup1.MODEL1.Fit.Height.ANOVA ------------- Output Added: ------------- Name: FitStatistics Label: Fit Statistics Template: Stat.REG.FitStatistics Path: Reg.ByGroup1.MODEL1.Fit.Height.FitStatistics ------------- Output Added: ------------- Name: ParameterEstimates Label: Parameter Estimates Template: Stat.REG.ParameterEstimates Path: Reg.ByGroup1.MODEL1.Fit.Height.ParameterEstimates ------------- NOTE: The above message was for the following BY group: Sex=F Output Added: ------------- Name: NObs Label: Number of Observations Template: Stat.Reg.NObs Path: Reg.ByGroup2.MODEL1.Fit.Height.NObs ------------- Output Added: ------------- Name: ANOVA Label: Analysis of Variance Template: Stat.REG.ANOVA Path: Reg.ByGroup2.MODEL1.Fit.Height.ANOVA ------------- Output Added: ------------- Name: FitStatistics Label: Fit Statistics Template: Stat.REG.FitStatistics Path: Reg.ByGroup2.MODEL1.Fit.Height.FitStatistics ------------- Output Added: ------------- Name: ParameterEstimates Label: Parameter Estimates Template: Stat.REG.ParameterEstimates Path: Reg.ByGroup2.MODEL1.Fit.Height.ParameterEstimates ------------- NOTE: The above message was for the following BY group: Sex=M NOTE: Interactivity disabled with BY processing. NOTE: PROCEDURE REG used (Total process time): real time 0.55 seconds cpu time 0.31 seconds
The important part for your question is the NAME for each. Notice that the tables in the log appear in the order they do in the results window. Then you modify the code of the procedure as:
proc reg data=work.class; by sex; model height=age; ods output parameterestimates=work.myestimates; run; quit;
to send the parameterestimates table to a data set work.myestimates.
Also if you read the documentation at https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=statug&docsetTarget=statu...
you will see that Proc Reg has an option OUTEST= that creates a data set with parameter estimates. You could add to the PROC statement OUTEST=work.myparmestimates or whatever.
You may ask why I showed the longer form first. Not all procedures have output data set options (Surveyreg for example) and there are many different tables that procedures can generate. Those that do have some output datasets do not always have one that sends what you may want to a data set. But the ODS OUTPUT will work.
Thank you for the help and detailed explanation. The ODS Output worked perfectly and I appreciate the longer detailed explanation for my own knowledge as well!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.