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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3982 views
  • 1 like
  • 2 in conversation