BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AllSoEasy
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
CTorres
Quartz | Level 8

value=value+(100*_N_);

AllSoEasy
Obsidian | Level 7

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

VD
Calcite | Level 5 VD
Calcite | Level 5

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;

AllSoEasy
Obsidian | Level 7

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1195 views
  • 4 likes
  • 3 in conversation