BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
batool89
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Just to be clear, you want a variable containing the number of pbservations used within each by group in the regression?

batool89
Fluorite | Level 6
yes, this is what i want
PeterClemmensen
Tourmaline | Level 20

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.

PeterClemmensen
Tourmaline | Level 20

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;
batool89
Fluorite | Level 6
thank you for your response. my regression is a little bit more complicated that requires doing regression for each firm in each year.
the problem was in having the same error degrees of freedom every year, so i wanted a command that prints the number of observation explicitly so i can check my results.
i used this equation before and it worked.
i have just found that the problem is in some of the sample observations.
thank you again 🙂 and have a nice day



SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 4336 views
  • 1 like
  • 2 in conversation