简体   繁体   中英

Convert string to number for large and small numbers sas

I have a problem in sas. I have a dataset where the numbers are stored as string. The problem is that the size and format of the numbers vary a lot. I will give an example:

 data s;
   x='123456789012345';
   y=input(x,best32.);
   z = '0.0001246564';
   a = input(z,best32.);
   put 'a='y;
   put a;
   keep y a;
run;

Output:

y=
1.2345679E14
a=
0.00012465644

As you can see I lose information in the large integer. How can I make my program in order to not lose information. As far as I understand this number has less than 15 digits sas large number . I really miss python where I just can set y = float(x).

No loss of information has occurred. You're just mistaking informat for format .

The informat best32. told SAS to import the string with a 32 width. All good, you have all 15 characters stored in the number.

Now if you want to see all 15 characters, you need to use a format wider than the default best12. format to see it on output:

 data s;
   x='123456789012345';
   y=input(x,best32.);
   z = '0.0001246564';
   a = input(z,best32.);
   put y= best32.;
   put a= best32.;
   keep y a;
run;

But even if you don't display it this way, the number y still is exactly equal to 123456789012345, if you were to do math with it or similar - you haven't lost any information, you just weren't displaying it right.

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