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
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.
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.
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.
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.