Help using Base SAS procedures

How can I do this type of regression?

Reply
Contributor
Posts: 24

How can I do this type of regression?

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.

PROC Star
Posts: 7,363

Re: How can I do this type of regression?

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)

Super User
Posts: 17,829

Re: How can I do this type of regression?

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;

Respected Advisor
Posts: 4,649

Re: How can I do this type of regression?

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

PG
Super User
Posts: 17,829

Re: How can I do this type of regression?

You can tell the Canadians today....

PROC Star
Posts: 7,363

Re: How can I do this type of regression?

I couldn't talk my wife into doing two thanksgivings this year.  Anyone have a spare turkey leg?

P.S.: I like your solution

Super User
Posts: 9,681

Re: How can I do this type of regression?

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

Respected Advisor
Posts: 4,649

Re: How can I do this type of regression?

A view doesn't generate any data. At least, it doesn't have to. - PG

PG
Super User
Posts: 9,681

Re: How can I do this type of regression?

PG,

Yeah, But when you implement PROC REG ,it will produce lots of obs in a dataset.

Respected Advisor
Posts: 4,649

Re: How can I do this type of regression?

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

PG
Super User
Posts: 9,681

Re: How can I do this type of regression?

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

Respected Advisor
Posts: 4,649

Re: How can I do this type of regression?

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

PG
Super User
Posts: 9,681

Re: How can I do this type of regression?

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

Respected Advisor
Posts: 4,649

Re: How can I do this type of regression?

Please check section Performance Considerations in

http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#n07vq6hmss6f67n1vhnn...

It states that when only sequential access is required, no actual dataset is created when reading a data step view.

PG

PG
Super Contributor
Posts: 1,636

Re: How can I do this type of regression?

Hi Art,

Sorry, no spare turkey leg from me. You can have something else, enjoy it! - Linlin

Attachment
Ask a Question
Discussion stats
  • 18 replies
  • 915 views
  • 1 like
  • 7 in conversation