BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

I am working on a research project and have trouble come up with a way to conduct a rolling window regression. In my proc model I include this macro to do my rolling window.

%do fen = %eval(&dfen) %to 100;

where %eval(&fen) le obs le %eval(36+&fen-1);

However, my proc model is done by id and as you can see in this macro I suppose that the number of observations is 100 for each id but this is not true I have a different number of observation for each id. In my database I add a column which indicates the number of total number of observation for each id (nb).

How can I change the fixed number 100 to a changing variables called nb?

I try to do it like this :

%do fen = %eval(&dfen) %to %eval(&nb);

where %eval(&fen) le obs le %eval(36+&fen-1);

but I have this error

ARNING: Apparent symbolic reference NB not resolved.

ERROR: The text expression &NB contains a recursive reference to the macro variable NB.  The

       macro variable will be assigned the null value.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

In case my example wasn't sufficiently clear, here is the same type of code for doing proc reg on sashelp.class using rolling windows of 5 records within each sex. BTW, you appear to never mark your questions as having been answered, thus many of us continue to spend probably unnecessary time on them:

filename runit temp;

data _null_;

  length script $255;

  file runit;

  set test (keep=sex);

  by sex;

  if first.sex then do;

    grp=0;

    counter=1;

  end;

  else counter+1;

  if counter ge 5 then do;

    grp+1;

    script=catt('Title "Predicting age by height and weight -- Sex=',

     sex,' group=',grp,'";');

    put script;

    script=catt("proc reg data=test (firstobs=",_n_-4," obs=",_n_,

     "); model age=height weight; run;");

    put script;

  end;

run;

%include runit;

View solution in original post

3 REPLIES 3
ballardw
Super User

This forum works best when only a single thread is opened for a give topic. If a suggestion is made to post in another subject area that's okay, but generally multiple threads are not needed.

art297
Opal | Level 21

In case my example wasn't sufficiently clear, here is the same type of code for doing proc reg on sashelp.class using rolling windows of 5 records within each sex. BTW, you appear to never mark your questions as having been answered, thus many of us continue to spend probably unnecessary time on them:

filename runit temp;

data _null_;

  length script $255;

  file runit;

  set test (keep=sex);

  by sex;

  if first.sex then do;

    grp=0;

    counter=1;

  end;

  else counter+1;

  if counter ge 5 then do;

    grp+1;

    script=catt('Title "Predicting age by height and weight -- Sex=',

     sex,' group=',grp,'";');

    put script;

    script=catt("proc reg data=test (firstobs=",_n_-4," obs=",_n_,

     "); model age=height weight; run;");

    put script;

  end;

run;

%include runit;

sasphd
Lapis Lazuli | Level 10

thanks for your help.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 3 replies
  • 2352 views
  • 0 likes
  • 3 in conversation