The macro variable &sysprocessid returns a 32 bit hexadecimal string.
Is there a way to conver it to a decimal string;
My code
data _null_;
temp=input(&sysprocessid.,best12.);
%put temp=;
run;
gives an error
Since I'm now back in front of my SAS, I can give you this advice:
Instead of &sysprocessid, use &sysjobid. On a UNIX system, it is the operating system's process number (I guess/hope it's the same on Windows); as it is a longint, it's easily stored as a number, and you can immediately identify your process in the process list with it.
It is as unique as the sysprocessid, and more useful.
Apparently, the first 16 bytes of the sysprocessid are a timestamp indicating the time when the process was started:
%let timestamp=%sysfunc(inputn(%substr(&sysprocessid.,1,16),hex16.),e8601dt20.);
%put ×tamp.;
Since a number in SAS is stored in 8 bytes (and not even all of those are used for the mantissa), you can't reliably convert the 16 bytes (represented by a 32-character hex string) to a number.
With a little fiddling around, you can find out how the process number of the operating system is coded into sysprocessid. The process number is a longint, stored in just 32 bits/4 bytes.
The short answer, already explained by @Kurt_Bremser, is NO.
A longer answer is two-fold:
1. The W. informat you're trying to use doesn't interpret hex representation input.
You'd have to either:
(a) Use the HEXw. informat as input ("&sysprocessid", hex32.) - but it will fail since the informat's length cannot be over 16.
(b) Use the PIBw. informat as input ("&sysprocessid"x, pib16.) - which will fail as well since its length W cannot be over 8.
Note that in both cases, even if the input string were within the prescribed informat length limits, precision would be lost as soon as the result would exceed the integer precision of the SAS numeric variable (i.e. ~9e+15 under ASCII).
2. The computation needed to convert your hex digit string into the decimal digit string is:
7441DBADC37C0DCF424018000000000000 = (7 × 16³³) + (4 × 16³²) + (4 × 16³¹) + (1 × 16³⁰) + (13 × 16²⁹) + (11 × 16²⁸) + (10 × 16²⁷) + (13 × 16²⁶) + (12 × 16²⁵) + (3 × 16²⁴) + (7 × 16²³) + (12 × 16²²) + (0 × 16²¹) + (13 × 16²⁰) + (12 × 16¹⁹) + (15 × 16¹⁸) + (4 × 16¹⁷) + (2 × 16¹⁶) + (4 × 16¹⁵) + (0 × 16¹⁴) + (1 × 16¹³) + (8 × 16¹²) + (0 × 16¹¹) + (0 × 16¹⁰) + (0 × 16⁹) + (0 × 16⁸) + (0 × 16⁷) + (0 × 16⁶) + (0 × 16⁵) + (0 × 16⁴) + (0 × 16³) + (0 × 16²) + (0 × 16¹) + (0 × 16⁰) = 39560295019911646378766846556315379040256
As you may have guessed, software other than SAS has been used to generate the result. With a modicum of careful (and not quite so simple) programming it can be done in SAS, too, by carefully emulating the arithmetic operations one or a few digits at a time and storing the interim results in a digit string, so that in the end it would look like the result above (or by calling a non-SAS module capable of handling big arithmetic). But even if you did that, it would go back to the @Kurt_Bremser's point since it can be stored in a SAS numeric variable only approximately as ~3.956e+40 at a significant loss of precision and, consequently, at a loss of disambiguation between different process IDs.
Paul D.
@hashman - congrats on a very impressive answer! And as already mentioned by others, sysprocessid is simply a key to a process and has no intrinsic meaning in itself. The decimal equivalent isn't useful for anything except maybe as an interesting intellectual challenge to calculate.
Since I'm now back in front of my SAS, I can give you this advice:
Instead of &sysprocessid, use &sysjobid. On a UNIX system, it is the operating system's process number (I guess/hope it's the same on Windows); as it is a longint, it's easily stored as a number, and you can immediately identify your process in the process list with it.
It is as unique as the sysprocessid, and more useful.
Apparently, the first 16 bytes of the sysprocessid are a timestamp indicating the time when the process was started:
%let timestamp=%sysfunc(inputn(%substr(&sysprocessid.,1,16),hex16.),e8601dt20.);
%put ×tamp.;
I would Like to thank all and hashman and KurtBremser for their wonderful replies.
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!
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.