0
votes

i have a data that contain 30 variable and 2000 Observations. I want to calculate regression in a loop, whan in each step I delete the i row in the data. so in the end I need thet my output will be 2001 regrsion, one for the regrsion on all the data end 2000 on each time thet I drop a row.

I am new to sas, and I tray to find how to do it withe macro, but I didn't understand.

Any comments and help will be appreciated!

2
Welcome to StackOverflow, you would recommend to read this guide for Minimal, Complete, and Verifiable example and modify your question in order to help users to understand your problem.Laura
This is known as a jackknife estimate, leave one out. If you have SAS/IML you can use the code here blogs.sas.com/content/iml/2017/06/21/…Reeza
Otherwise there's a jackknife and bootstrap macro here: support.sas.com/kb/24/982.html And if you need references, there's a really good paper called Don't be Loopy by David Cassell that's worth reading. It's highly useful.Reeza

2 Answers

1
votes

This will create the data set I was talking about in my comment to Chris.

data del1V /view=del1v;
   length group _obs_ 8;
   set sashelp.class nobs=nobs;
   _obs_ = _n_;
   group=0;
   output;
   do group=1 to nobs;
      if group eq _n_ then;
      else output;
      end;
   run;
proc sort out=analysis;
   by group;
   run;
0
votes
DATA NEW;
  DATA OLD;
  do i = 1 to 2001;
    IF _N_ ^= i THEN group=i;
    else group=.;
    output;
  end;
proc sort data=new;
  by group;
proc reg syntax;
  by group;
run;

This will create a data set that is much longer. You will only call proc reg once, but it will run 2001 models.

Examining 2001 regression outputs will be difficult just written as output. You will likely need to go read the PROC REG support documentation and look into the output options for whatever type of output you're interested in. SAS can create a data set with the GROUP column to differentiate the results.

I edited my original answer per @data null suggestion. I agree that the above is probably faster, though I'm not as confident that it would be 100x faster. I do not know enough about the costs of the overhead of proc reg versus the cost of the group by statement and a larger data set. Regardless the answer above is simpler programming. Here is my original answer/alternate approach.

You can do this within a macro program. It will have this general structure:

%macro regress;
  %do i=1 %to 2001;
    DATA NEW;
      DATA OLD;
      IF _N_=&I THEN DELETE;
    RUN;
    proc reg syntax;
    run;
  %end;
%mend;
%regress

Macros are an advanced programming function in SAS. The macro program is required in order to do a loop of proc reg. The %'s are indicative of macro functions. &i is a macro variable (& is the prefix of a macro variable that is being called). The macro is created in a block that starts and ends with %macro / %mend, and called by %regress.

Examining 2001 regression outputs will be difficult just written as output. You will likely need to go read the PROC REG support documentation and look into the output options for whatever type of output you're interested in. Use &i to create a different data set each time and then append together as part of the macro loop.