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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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