@DavidLie wrote:
Hi all,
I have a sample of 40 observations. The plan is to:
Take the first 20 observations (i.e., obs 1 to 20).
Run a regression
Keep the result
Take the next 20 observation (i.e., obs 2 to 21).
Repeat until you reach the maximum (i.e., obs 21 to obs 40).
Any help will be greatly appreciated. If possible, I would like to keep the line as little as possible as I have quite a lot of observations.
Thanks in advance.
Best, David
data have;
input x1 x2 y;
datalines;
69 0.901225752 0.535917754
26 0.979065064 0.328516725
21 0.462043623 0.928984209
70 0.372254307 0.020944067
26 0.70178162 0.015753384
22 0.755669857 0.287674489
45 0.621848244 0.876177263
23 0.049950103 0.524321342
75 0.323187042 0.458245799
62 0.988737694 0.528055761
59 0.047655873 0.637754194
59 0.499943648 0.997049298
25 0.597043632 0.556921095
92 0.679854964 0.433165676
29 0.686543133 0.720057785
35 0.861474371 0.344762962
79 0.591574823 0.876250534
53 0.741976868 0.430488835
71 0.146723447 0.605425714
75 0.435811738 0.861299126
96 0.785859466 0.717045755
99 0.520055579 0.784497337
58 0.394083913 0.712998746
61 0.875958722 0.667760878
15 0.561292166 0.836592031
56 0.652887463 0.236309836
9 0.344428535 0.224147253
6 0.785126736 0.435528686
72 0.847421203 0.160322663
78 0.663642034 0.466674263
83 0.333921138 0.029331531
77 0.486751999 0.706800698
92 0.801502963 0.788823137
9 0.578615463 0.347239912
41 0.053458445 0.094070384
68 0.251134914 0.103399917
2 0.49184594 0.102494486
97 0.120083405 0.055981267
78 0.5423958 0.181672902
17 0.834739212 0.142969285
;
run;
You want to create a data set (or view) with each observation group identified with a variable that can be used in a BY statement for the stat proc you want to call. That will be more efficient that looping the whole process as you describe above.
data have;
infile cards expandtabs;
_obs_=_n_;
input x1 x2 y;
datalines;
69 0.901225752 0.535917754
26 0.979065064 0.328516725
21 0.462043623 0.928984209
70 0.372254307 0.020944067
26 0.70178162 0.015753384
22 0.755669857 0.287674489
45 0.621848244 0.876177263
23 0.049950103 0.524321342
75 0.323187042 0.458245799
62 0.988737694 0.528055761
59 0.047655873 0.637754194
59 0.499943648 0.997049298
25 0.597043632 0.556921095
92 0.679854964 0.433165676
29 0.686543133 0.720057785
35 0.861474371 0.344762962
79 0.591574823 0.876250534
53 0.741976868 0.430488835
71 0.146723447 0.605425714
75 0.435811738 0.861299126
96 0.785859466 0.717045755
99 0.520055579 0.784497337
58 0.394083913 0.712998746
61 0.875958722 0.667760878
15 0.561292166 0.836592031
56 0.652887463 0.236309836
9 0.344428535 0.224147253
6 0.785126736 0.435528686
72 0.847421203 0.160322663
78 0.663642034 0.466674263
83 0.333921138 0.029331531
77 0.486751999 0.706800698
92 0.801502963 0.788823137
9 0.578615463 0.347239912
41 0.053458445 0.094070384
68 0.251134914 0.103399917
2 0.49184594 0.102494486
97 0.120083405 0.055981267
78 0.5423958 0.181672902
17 0.834739212 0.142969285
;
run;
%let s = 20; /*sample size*/
data analysis / view=analysis;;
s = &s;
f = 1;
l = s;
do w = 1 by 1 while(l le nobs);
do i = f to l while(l le nobs);
set have nobs=nobs point=i;
output;
end;
f = f+1;
l = l+1;
end;
call symputx('w',w-1);
stop;
run;
%put NOTE: &=w;
sasfile have load;
proc reg noprint data=analysis outest=est;
by w;
model y = x: / aic bic edf;
run;
sasfile have close;
proc print data=est;
run;
... View more