BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sajid01
Meteorite | Level 14

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

data _null_;
74 temp=input(&sysprocessid.,best12.);
NOTE: Line generated by the macro variable "SYSPROCESSID".
74 41DBADC37C0DCF424018000000000000
______________________________
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN,
LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.
 
75 %put temp=;
temp=
76 run;
 
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
1:1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
 
 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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 &timestamp.;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

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.

Peter_C
Rhodochrosite | Level 12
It is possible that the sysprocessID is unique but meaningless. In that case there is no need to decodeit into a number, to use it as a key. To display the value in a readable (but meaningless) way, use the $HEX format with a suitable width (rtfm)
hashman
Ammonite | Level 13

@Sajid01:

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.

SASKiwi
PROC Star

@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.

Kurt_Bremser
Super User

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 &timestamp.;
Sajid01
Meteorite | Level 14

I would Like to thank all and hashman and KurtBremser for their wonderful replies.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 1355 views
  • 6 likes
  • 5 in conversation