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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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