BookmarkSubscribeRSS Feed
deleted_user
Not applicable
just wanted to share the "out of the box" moment.
&SYSINDEX is clearly documented "You can use SYSINDEX in a program that uses macros when you need a unique number that changes after each macro invocation."
I wanted a unique number when some conditions occurred in a macro and thought of &SYSINDEX. but it only created a constant 😞 .
This time the light bulb switched on and I saw out of the box 😉 I should use %SYSINDEX .
OK, I know that does not exist, but it is simple enough to create[pre] %macro sysindex ;
&sysindex
%mend sysindex ;[/pre]So I only needed to change that "&" prefix into "%" before the SYSINDEX and obtained exactly what I needed.
Every invocation of %sysindex provides a unique number for the SAS session. 🙂

regards to the Forum

PeterC
3 REPLIES 3
data_null__
Jade | Level 19
Alternatively:

[pre]
%sysfunc(monotonic())
[/pre]

More typing but then you don't need to maintain a macro that provides very little function.
deleted_user
Not applicable
having the %SYSINDEX feels better, as it is a good match for the documentation.
In on-line help and Doc, I can't find monotonic.
On SAS Support site, it is declared as not supported in SQL

So I feel more confident about leaving %sysindex in client autocall libraries.
Would you not agree?

PeterC
PatrickG
SAS Employee
The monotonic() function is undocumented (which is why you can't find it!). This is because it can be problematic and produce unexpected results in some cases, e.g. when used within PROC SQL. So if you go that route, be careful!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1701 views
  • 0 likes
  • 3 in conversation