## Elementary question regarding data step iteration

Solved
Frequent Contributor
Posts: 109

# Elementary question regarding data step iteration

Hello guys,

Apologies if this is a very elementary question, but I've been scouring my SAS reference book as well as the online support pages/google for an answer and haven't found an easy way to do this yet...So:

While iterating over a dataset via a datastep, I want to be able to keep a counting variable and increase its value after each observation within the data step. I.e: I want to increase the numeric value of a column cell by 100 in the first observation, 200 in the second, 300 in the third, and so on...My thought was to just use a global macro initially set to 100, and add 100 to it via symput("var" (value + 100)); or via %let assignments, but the value of the variable remains constant throughout all obervations of the datastep in both of my attempts...Surely such an elementary capability can't be such a difficult process right? Am I just missing something simple here?

Please let me know if anyone has an idea.

Thanks a lot guys, I appreciate your time!

-Ryan

Accepted Solutions
Solution
‎02-07-2013 04:18 PM
Regular Contributor
Posts: 180

## Re: Elementary question regarding data step iteration

value=value+(100*_N_);

All Replies
Solution
‎02-07-2013 04:18 PM
Regular Contributor
Posts: 180

## Re: Elementary question regarding data step iteration

value=value+(100*_N_);

Frequent Contributor
Posts: 109

## Re: Elementary question regarding data step iteration

Ah ha! I knew it couldn't be too complicated. Thanks a lot CTorres, really appreciate it!

Frequent Contributor
Posts: 94

## Re: Elementary question regarding data step iteration

Hi, I am sorry I am aware that this has been answered but just in case you were not aware that the RETAIN keyword can be very useful for dealing with iterations. So, here your solution with RETAIN will be:

data two;

set one;

retain value 0;

value=value+100;

run;

Frequent Contributor
Posts: 109

## Re: Elementary question regarding data step iteration

Ahh I was not aware, but this is very useful information. Thank you!!

🔒 This topic is solved and locked.