BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ChickenLittle
Obsidian | Level 7

Hi,

 

I am trying to convert a character field to a numeric field without resulting in an exponent when the value is long.

 

Data:

obs    Field1

1          123456789012345

 

Code:

data Example;
set RawData;
Field2 = input(Field1, 16.);
run;

 

Result:

obs    Field2

1          1.23456E14

 

What I want as my result:

obs    Field2

1          123456789012345

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you input data with a 16. informat use a 16 wide FORMAT assigned to the value.

When you do not assign a format to a numeric value the default is BEST12. So stuffing 15 or 16 characters into 12 results in the Exponential display.

data Example;
Field2 = input('123456789012345', 16.);
format field2 best16.;
run;

 

Are these "numbers" actually a measurement or something that you will do arithmetic? If not leave them as character.

View solution in original post

4 REPLIES 4
ballardw
Super User

If you input data with a 16. informat use a 16 wide FORMAT assigned to the value.

When you do not assign a format to a numeric value the default is BEST12. So stuffing 15 or 16 characters into 12 results in the Exponential display.

data Example;
Field2 = input('123456789012345', 16.);
format field2 best16.;
run;

 

Are these "numbers" actually a measurement or something that you will do arithmetic? If not leave them as character.

ChickenLittle
Obsidian | Level 7

Thanks! And it is a key. But to spare me from modifying another original table, I'd rather just modify my table to match it.

ballardw
Super User

The format basically would have no impact on use such as joining a different table as I guess might be the use of something you call a key.

 

A somewhat silly example where one value is formatted as date to demonstrate that the format does not impact the join on the values.

data t1;
   input key value;
datalines;
12345  66
45612  99
;

data t2;
  input field1 othervalue;
  format field1 date9.;
datalines;
12345  99999
45612  88888
;

proc sql;
   create table example as
   select t1.*, t2.*
   from t1 as a
        left join
        t2 as b
   on t1.key=t2.field1
   ;
quit;
Tom
Super User Tom
Super User

You can store 16 digits as a number, but only up to the maximum integer that SAS can represent before it starts having to round values.  So unless you are positive the values will always be less than 9,007,199,254,740,992 you should keep it as character string.  There is no real reason to store identifiers as numbers since you won't be doing any arithmetic on them.

45   data _null_;
46     maxint=constant('exactint');
47     len = length(cats(maxint));
48     put len= maxint=:comma32.;
49   run;

len=16 maxint=9,007,199,254,740,992

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1192 views
  • 3 likes
  • 3 in conversation