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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.