DATA Step, Macro, Functions and more

SYSINDEX

Reply
N/A
Posts: 0

SYSINDEX

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
Respected Advisor
Posts: 3,777

Re: SYSINDEX

Alternatively:

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

More typing but then you don't need to maintain a macro that provides very little function.
N/A
Posts: 0

Re: SYSINDEX

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
SAS Employee
Posts: 58

Re: SYSINDEX

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!
Ask a Question
Discussion stats
  • 3 replies
  • 181 views
  • 0 likes
  • 3 in conversation