BookmarkSubscribeRSS Feed
DarthSAS
Calcite | Level 5
Hi all

I'm very new to the SAS World, but i have a little experience on t-sql. What i want to do is create a table or a data set with with an unique ID with an auto increment like t-sql do or a sequence like Oracle but with SAS.

I've heard of a surrogate key. Can i create un surrogate key to do this functionality ?
6 REPLIES 6
DerekAdams
Calcite | Level 5
Try using monotonic() in proc sql, i.e monotonic() as xxx or if using a datastep xxx = _n_;
DarthSAS
Calcite | Level 5
Thank you Derek,

I saw in another thread that the monotonic function is undocumented and can cause unexpected results........

Is that right or i can use it without lost or corrupt data ?
DerekAdams
Calcite | Level 5
I havent had any issues so far so I can't really comment on that at the moment
Cynthia_sas
SAS Super FREQ
Hi:
This is the Tech Support note on the use of the MONOTONIC function:
http://support.sas.com/kb/15/138.html

The full text of the note says:

The MONOTONIC() function is not supported in PROC SQL. Using the
MONOTONIC() function in PROC SQL can cause missing or non-sequential
values to be returned.


To me, this means that if you do use the MONOTONIC function, then you can't complain when/if it doesn't return sequential numbers.. I suspect that for simple, simple queries, you might be OK, but for more complex queries that involve joins and where clauses, you might get into the missing or non-sequential values.

My .02,
cynthia
Peter_C
Rhodochrosite | Level 12
I heard a logical explanation for concern about use of "monotonic()".
When an sql platform/optimiser/engine has enough information to multi-thread resolution of a query," monotonic()" may be implemented in parallel across threads. The result would not be what is desired.
For simple platforms and queries, that can be expected to single-thread, monotonic() should be able provide the unique id.

This scenario, where a feature cannot be expected to "universally" work, applies in other parts of SAS. For example the number of observations indicated by the NOBS= option on a SET statement, will be missing (or may even be negative) when the data set is a view or subject to a where clause.

PeterC
DarthSAS
Calcite | Level 5
Thank you,

Ok, and for the surrogate key. Can i generate this in Enterprise Guide when i'm creating a data set ?

Do you have some docs on how work a surrogate key in SAS ?

thx

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 8624 views
  • 0 likes
  • 4 in conversation