Is below doing what you're after?
data have;
do x=1 to 5;
y=x+2;
output;
end;
stop;
run;
/* get number of rows used as number of required array elements */
data _null_;
call symputx('nobs',nobs);
stop;
set have nobs=nobs;
run;
%put &=nobs;
data want(drop=_: vx_: vy_:);
if 0 then set have(keep=x y);
length result 8;
array vx_ {&nobs} 8;
array vy_ {&nobs} 8;
array step_ {&nobs} 8;
do while(not last);
set have end=last;
_i+1;
vx_[_i]=x;
vy_[_i]=y;
end;
do _i=1 to &nobs;
_sX=1;
_startY+1;
call missing(result, of step_{*});
do _sy=_startY to dim(vy_);
step_[_sx]=vx_[_sx]*vy_[_sy];
_sX+1;
end;
x=vx_{_i};
y=vy_{_i};
result=sum(of step_[*]);
output;
end;
stop;
run;
proc print data=want;
run;
Is below doing what you're after?
data have;
do x=1 to 5;
y=x+2;
output;
end;
stop;
run;
/* get number of rows used as number of required array elements */
data _null_;
call symputx('nobs',nobs);
stop;
set have nobs=nobs;
run;
%put &=nobs;
data want(drop=_: vx_: vy_:);
if 0 then set have(keep=x y);
length result 8;
array vx_ {&nobs} 8;
array vy_ {&nobs} 8;
array step_ {&nobs} 8;
do while(not last);
set have end=last;
_i+1;
vx_[_i]=x;
vy_[_i]=y;
end;
do _i=1 to &nobs;
_sX=1;
_startY+1;
call missing(result, of step_{*});
do _sy=_startY to dim(vy_);
step_[_sx]=vx_[_sx]*vy_[_sy];
_sX+1;
end;
x=vx_{_i};
y=vy_{_i};
result=sum(of step_[*]);
output;
end;
stop;
run;
proc print data=want;
run;
@smurray Below one way how to go for processing by group.
data have;
do group=1 to 3;
do x=1 to 5;
/* y=x+1+group;*/
y=x+2;
output;
if group=2 and x=3 then leave;
end;
end;
stop;
run;
/* get max number of rows in a group to define required array elements */
proc sql noprint;
select max(cnt) into :max_grp trimmed
from
(
select count(*) as cnt
from have
group by group
)
;
quit;
%put &=max_grp;
data want(keep=group x y result step_:);
if 0 then set have;
length result 8;
array vx_ {&max_grp} 8;
array vy_ {&max_grp} 8;
array step_ {&max_grp} 8;
do while(not last);
set have end=last;
by group;
_stop+1;
vx_[_stop]=x;
vy_[_stop]=y;
if last.group then
do;
do _i=1 to _stop;
_sX=1;
_startY+1;
call missing(result, of step_[*]);
do _sy=_startY to dim(vy_);
step_[_sx]=vx_[_sx]*vy_[_sy];
_sX+1;
end;
x=vx_{_i};
y=vy_{_i};
result=sum(of step_[*]);
output;
end;
call missing(of _all_);
end;
end;
stop;
run;
proc print data=want;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.