简体   繁体   中英

Big number anomaly in SAS

Do somebody know why the number stocked in "numero" isn't the same that the one I put in the let ?

I use SAS Enterprise Guide 7.1.

Here's my program :

%let ident = 4644968792486317489 ;

data _null_ ;
    numero= put(&ident.,z19.);
    call symputx('numero',numero);
run;

%put &numero. ;

And the log :

30         %let ident = 4644968792486317489 ;
31         
32         data _null_ ;
33          numero= put(&ident.,z19.);
34          call symputx('numero',numero);
35         run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

36         
37         %put &numero. ;
4644968792486317056

Thanks by advance !

SAS stores numbers as 8 byte floating point values. Therefore there is a limit to the maximum integer that can be stored exactly (or really exactly without gaps). They even publish a table with the maximum value .

在此处输入图片说明

And a function you can use to determine the maximum value.

3    %put %sysfunc(constant(exactint),comma23.);
9,007,199,254,740,992

Looks like your "number" is really an identifier. So store it as character to begin with and you will not have these problems.

data want;
  length numero $19;
  numero = "&ident";
  numero = translate(right(numero),'0',' ');
run;

Use the SAS MD5 function to anonymize strings. Don't forget MACRO is really just text processing.

%let ident = 4644968792486317489 ;
%let numero = %sysfunc(MD5(&ident));

or in DATA Step

data ... ;
  numero = MD5("&ident");

In certain situations you might associate a monotonic serial value to an identity value.

%let ident = 4644968792486317489 ;

%if not %symexist(i&ident) %then %do;
  %let i&ident = %sysfunc(monotonic());
  %put new serial;
%end;

%put i&ident=&&i&ident;
----- LOG -----
i4644968792486317489=1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM