Maybe like this:
data have;
input ID begin $;
array y[*] y_1201-y_1252 (1:52);
cards;
1 y_1203
2 y_1212
3 y_1248
;
run;
data want;
set have;
array y[*] y_:;
array week[1:12] week_6-week_1 week1-week6;
output = 0; j = 13;
do i = lbound(y) to hbound(y);
if vname(y[i]) = begin then
do;
output = 1;
j = i - 6;
leave;
end;
end;
if output then
do output = lbound(week) to hbound(week);
if lbound(y) <= j <= hbound(y) then week[output] = y[j];
j + 1;
end;
output;
keep id week:;
run;
proc print;
run;
Bart
... View more