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
value=value+(100*_N_);
value=value+(100*_N_);
Ah ha! I knew it couldn't be too complicated. Thanks a lot CTorres, really appreciate it!
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;
Ahh I was not aware, but this is very useful information. Thank you!!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: