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.
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;
%let j=%eval(&i.+&number.);
proc reg data=sashelp.class (firstobs=&i obs=&j.);
model age=height weight;
run;
quit;
%end;
%mend repeatreg;
%repeatreg(5,15)
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;
by sex;
model age=height weight;
run;
quit;
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;
output;
end;
end;
stop;
run;
proc reg data=rCars outest=eCars;
by grp;
model horsePower = enginesize;
run;
That way you don't create any new version of your dataset and you can collect all the results in a single dataset.
PG
You can tell the Canadians today....
ArthurT,
Actually I like your solution more than PG's . PG's code will generated lots of obs when it is a big data.
Ksharp
PG,
Yeah, But when you implement PROC REG ,it will produce lots of obs in a dataset.
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
Hi. PG,
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 ?
Ksharp
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
Hi, PG
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.
Regards.
Ksharp
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.
PG
Hi Art,
Sorry, no spare turkey leg from me. You can have something else, enjoy it! - Linlin
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.