HI,
I have the below requirement and wondering if this can be implemented in simple datastep loop:
will be starting with a simple dataset with two variable
input:
| x | y |
| 1 | 0 |
logic:
| x | y | z |
| 1 | 0 | x+y |
| prev z | prev y +1 | x+y |
| prev z | prev y +1 | x+y |
desired output:
| x | y | z |
| 1 | 0 | 1 |
| 1 | 1 | 2 |
| 2 | 2 | 4 |
| 4 | 3 | 7 |
| 7 | 4 | 11 |
Hi @koya,
@koya wrote:
... wondering if this can be implemented in simple datastep loop
Yes, this is possible. Wondering why you don't just start writing that data step.
data have;
x=1; y=0;
run;
data want;
set have;
do _n_=1 to 5;
z=x+y;
output;
x=z; y+1;
end;
run;
/* Or even simpler: */
data want;
set have;
do y=y to 4;
z=x+y;
output;
x=z;
end;
run;
Hi @koya,
@koya wrote:
... wondering if this can be implemented in simple datastep loop
Yes, this is possible. Wondering why you don't just start writing that data step.
data have;
x=1; y=0;
run;
data want;
set have;
do _n_=1 to 5;
z=x+y;
output;
x=z; y+1;
end;
run;
/* Or even simpler: */
data want;
set have;
do y=y to 4;
z=x+y;
output;
x=z;
end;
run;
data want; x=1;y=0;z=x+y;output; do i=1 to 10; x=z;y=y+1;z=x+y;output; end; drop i; run; proc print;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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.