Help using Base SAS procedures

SAS macro; sysfunction; identifier auto increment

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

SAS macro; sysfunction; identifier auto increment

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


Accepted Solutions
Solution
‎08-04-2016 06:10 PM
Super User
Super User
Posts: 7,059

Re: SAS macro; sysfunction; identifier auto increment

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


All Replies
Super User
Posts: 11,343

Re: SAS macro; sysfunction; identifier auto increment

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.

 

 

Contributor
Posts: 38

Re: SAS macro; sysfunction; identifier auto increment

thanks very much for your insight!
Solution
‎08-04-2016 06:10 PM
Super User
Super User
Posts: 7,059

Re: SAS macro; sysfunction; identifier auto increment

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

shock_no=shock_no+1; 
Contributor
Posts: 38

Re: SAS macro; sysfunction; identifier auto increment

thank you!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 239 views
  • 0 likes
  • 3 in conversation