Creating a somewhat unique ID using the UUIDGEN function


According to the Daily Writing Tips blog, describing a thing as "somewhat unique" is bad form. Unique means "one of a kind", so either it is or it is not. The famous example (which the style police will use to chide you) is that you can't have something as "somewhat unique" any more than a woman can be "somewhat pregnant".

But when programming and dealing with computers, we often deal with the concept of "unique enough". And to fill that niche, we have the Globally Unique Identifiers, or GUIDs. (Most people pronounce this "GOO-ids".) These are also called UUIDs, for "universal unique identifiers". (But the Universe is pretty big, isn't it? Therefore using this term makes a pretty bold claim.)

A GUID is a 128-bit value, allowing for 2128 (or 3.4028237e+38) possibilities. Computer processes generate GUIDs behind the scenes all of the time for lots of purposes, and among geeks we joke that they will become a scarce resource, like helium. But rest assured: it will take us a long time to go through all of the possible GUID values.

When we see GUID values in the wild, they are usually expressed as a series of 32 hexadecimal characters, often containing hyphens like a crazy sort of phone number (as if you might attempt to commit it to memory):


I created the above GUID fresh for this blog (it's never been seen before!) using a tool on my PC called uuidgen, which is part of the Windows SDK.

In the SAS world, I can use the UUIDGEN function to create these as needed from within my SAS program:

data wastedGuids;
do x=1 to 10;
  guid = uuidgen();


The UUIDGEN function relies on code libraries that are system-dependent, as there are different algorithms for creating GUID values. When I run the above program on a Linux version of SAS, I get a different pattern of results:

I suppose -- now that I've promoted this function on the blog -- we'll have SAS programmers cranking GUIDs out day-and-night. At this rate, will there be any GUIDs left for our grandchildren? Well, I can't worry about that -- live for today, I say.

Bonus joke: How do you catch a unique rabbit? (Reply in the comments, please.)


About Author

Chris Hemedinger

Senior Manager, SAS Online Communities

+Chris Hemedinger is the manager of SAS Online Communities. He's also co-author of the popular SAS for Dummies book, author of Custom Tasks for SAS Enterprise Guide using Microsoft .NET, and a frequent participant on the SAS Enterprise Guide discussion forum.

Related Posts


  1. You’ve got me hooked! I’ll take a couple of 100M of these GUIDS. Forget about incrementing keys when upserting tables. You’ve just added a new requirement for DIS R&D.

    Your joke though is a true challenge. I’ve looked it up on Internet but my English is not good enough to get the answer (at least I hope it’s my English).

    Thanks for another of your great blogs.

  2. I had to search for the punchline to the joke, and will leave it for others to find.

    I've been wasting UUIDs for years - we have a macro that sends SAS log output to a file using Proc Printto. As well as a macro variable to describe the process being logged (_out), the log file names contain the first eight characters returned from a call to uuidgen() so that re-running code doesn't replace log files generated from earlier runs:

       %let uuid = %sysfunc(substr(%sysfunc(uuidgen(1, 0)), 1, 8));
       proc printto log = "&_out..&uuid..log" new;
       filename logfile "&_out..&uuid..log";

    Eight hex characters give me unique enough filenames and lets me 'neek up on any pesky errors.

  3. Peter Lancashire on

    You'd catch a unique rabbit the same way as any rabbit: they are all unique; unless they've developed cloning in the burrows.

  4. Thanks Chris, I used the info in your post to create a somewhat unique tablename:

    /* Create unique tablename. */
    data _null_;
         tablename = substr(cat("MO", compress(uuidgen(),"-")),1,30);
         call symput('tablename', tablename);

Leave A Reply

Back to Top