11-22-2012 04:05 PM
I have several thousand observations. I want a code for a regression that would work like a moving average; i need a regression for obs 1 through 200, then a regression for obs 2 through 201, then 3 through 202, etc etc. Is this possible to do without making a seperate sample for each regression? Any idea what the coding would look like?
Thanks in advance.
11-22-2012 04:25 PM
Not sure if there is a more direct way, but you could always wrap the reg call in a macro. E.g., given sashelp.class which has 19 records, the following would run regressions on records 1 thru 5, then 2 thru 6, etc, thru 15 thru 19:
%macro repeatreg (number,lastset);
%do i=1 %to &lastset;
proc reg data=sashelp.class (firstobs=&i obs=&j.);
model age=height weight;
11-22-2012 04:44 PM
use by groups after classifying your observations into groups, you can use proc format to help.
proc sort data=sashelp.class; by sex;
proc reg data=sashelp.class;
model age=height weight;
11-22-2012 04:55 PM
Or use a view and POINT=
data rCars(keep=grp engineSize horsepower) / view=rCars;
do grp = 0 to nbCars-200;
do j = 1 + grp to 200 + grp;
set sashelp.cars nobs=nbCars point=j;
proc reg data=rCars outest=eCars;
model horsePower = enginesize;
That way you don't create any new version of your dataset and you can collect all the results in a single dataset.
11-26-2012 11:42 AM
There won"t be much data produced unless you include an OUTPUT statement (to get predicted values or residuals). The OUTEST=eCars option produces a single observation per regression. You can also request the NOPRINT option to suppress printed output. - PG
11-26-2012 09:37 PM
I do not think so.
when you implement REG , data=rCars will generate a concrete dataset even you cann't see it .
View only contains the sas code you wrote before, when sas use reg model ,it will also need a real dataset to feed REG. View can't do it , I guess so. Did you make a experiment for it ?
11-27-2012 11:57 AM
I tested both solutions that I proposed. I can't tell if a hidden dataset is created by executing the view or if some other kind of interprocess communication is used. It might depend on its size. - PG
11-27-2012 10:14 PM
I believe a concrete dataset in somewhere, VIEW only contains the sas code ,you can't feed it into REG .
when you execute PROC REG ,sas will generate a dataset to feed it . You can't walk around it by using View.
12-11-2012 11:13 AM
Please check section Performance Considerations in
It states that when only sequential access is required, no actual dataset is created when reading a data step view.