data test; /* create a sample dataset */
format date date1 date2 date9.;
date1 = '01jan2000'd; /* start of random date */
date2 = '31dec2012'd; /* end of random date */
do i = 1 to 1000; /* create 1000 sample */
date = date1 + floor(ranuni(12345)*(date2-date1+1)); /* create random date */
value = int(ranuni(345)*100); /* random value between 1 and 100) */
type = floor(ranuni(789)*10); /* random value of type between 1 to 10 */
output;
end;
drop date1 date2 i;
run;
proc sort data=test nodupkey; /* remove the duplicated date */
by date;
run;
data test_n;
set test;
n=_n_; /* add row number n */
run;
data Test_OutName (drop=n1 n2);
set test_n;
if type = 1 and n > 20 then do;
n1 = n-20;
n2 = n+20;
OutName = cats("Out", put(n,3.));
call execute('data '||OutName||'; set test_n(firstobs='||n1||' obs='||n2||'); run;');
end;
run;