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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.