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

Hi all,

 

I have a variable that gets incremented:

 

shock_number =1

shock_number=2

 

and so on. basically I manually increment dependent on adding a shock multiplier to each column. A selection:

 

 

_base_state=state;

 state="FL"; shock_no=1; shock_desc="state=FL"; output;

 state="CA"; shock_no=2; shock_desc="state=CA"; output;

 state="NY"; shock_no=3; shock_desc="state=NY"; output

state=_base_state;

 

*as of date;

_base_aod=as_of_date;

as_of_date=intnx('month',as_of_date,1); shock_no=4; shock_desc="aod_+1mo"; output;

as_of_date=intnx('month',as_of_date,-2); shock_no=5; shock_desc="aod_-1mo"; output;

as_of_date=_base_aod;

 

 

 

And so on. I'm doing this shock entry for a hundren more columns. Instead of having to manually enter the shock_number for each new shock, is there a code snippet that would automatically pick up the last shock_no used and increment by 1?

 

Thank you very much in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you want to increase the value of a variable by 1 then just add 1 to it.

shock_no=shock_no+1; 

View solution in original post

4 REPLIES 4
ballardw
Super User

It is not clear whether you need the value to persist from record to record.

It really helps to have begining input data and what the result should be. Please reduce the data to only what is needed to demonstrate the issue.

 

This link https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... has instructions on how to create datastep code that we can use to create a working data set to test code.

 

 

blakezen
Obsidian | Level 7
thanks very much for your insight!
Tom
Super User Tom
Super User

If you want to increase the value of a variable by 1 then just add 1 to it.

shock_no=shock_no+1; 
blakezen
Obsidian | Level 7
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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1405 views
  • 0 likes
  • 3 in conversation