hello,
I am using a macro to conduct regression analysis using sas 9.4. the goal is to have results for every firm-year, here is the program:
%* run regression for each subsample by cusip and store estimation in a file with year identifier.;
proc reg data=one outest =two noprint ;
by cusip;
model dependent_var = independent1 independent2;
run;
data out_&fyear.;
set two;
fyear=&fyear.;
run;
%mend;
my question is how can I have the number of observation in the outest file (two)?
i used EDF command but it gives me the number of regressors in the model not the number of observations regressed.
thank you in advance
Use this small example and drop the variables you dont want
proc sort data = sashelp.class;
by sex;
run;
proc reg data=sashelp.class noprint outest=est;
by sex;
model height=weight / sse;
run;
data est;
set est;
nObs = _P_ + _EDF_;
run;
Just to be clear, you want a variable containing the number of pbservations used within each by group in the regression?
You can do this by adding the variables _P_ and _EDF_ to the outest dataset. These are the number of parameters estimated, including the intercept and the error degrees of freedom, which when summed together gives the number of observations.
Use this small example and drop the variables you dont want
proc sort data = sashelp.class;
by sex;
run;
proc reg data=sashelp.class noprint outest=est;
by sex;
model height=weight / sse;
run;
data est;
set est;
nObs = _P_ + _EDF_;
run;
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.