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!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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