Hi, I am trying to copy a number from one column to another
data MS_MAIN_INPUT; set MS_MAIN_INPUT_0; retain new_CPFN; if MARCA="A" then new_CPFN = CPFN; if MARCA="N" then new_CPFN = CPFN_old; run;
But it seems that the number loses some digits when doing the copy.
If I export to CSV this table I see that the number is different
How can I keep all the digits?
Thanks for your help!
Assign a proper format (e.g. 32.).
But your numbers with 16 digits are right on the verge of numeric precision (SAS stores numbers in 8 byte real).
If these are in fact codes and not numbers, they should be stored as character when the data is read into SAS.
SAS cannot represent exactly numbers that are 15 digits long (or longer), and so "rounding" occurs.
Numbers such as this should be character strings, and then the problem goes away.
Assign a proper format (e.g. 32.).
But your numbers with 16 digits are right on the verge of numeric precision (SAS stores numbers in 8 byte real).
If these are in fact codes and not numbers, they should be stored as character when the data is read into SAS.
Thank You!
I am trying to change into character but I don't get the whole number. How can I do it?
data want; set tables; retain new_CPFN; if MARCA="A" then new_CPFN = put(CPFN, 18.); if MARCA="N" then new_CPFN = put(CPFN_old, 18.); run;
Looks like you already defined NEW_CPFN in the source dataset and the length defined for it is not long enough to store an 18 digit string.
Check this example:
2892 data test; 2893 length number1 number2 8 string1 string2 $8 string3 $18; 2894 number1=1234567890123 ; 2895 number2=put(number1,18.); 2896 string1=put(number1,18.); 2897 string2=put(number1,18.-L); 2898 string3=put(number1,18.); 2899 format number: best18. string: $quote. ; 2900 put (_all_) (=/); 2901 run; NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 2895:11 number1=1234567890123 number2=1234567890123 string1=" 123" string2="12345678" string3=" 1234567890123"
Thanks! That was it!
Are you doing arithmetic with the variables CPFN or new_CPFN? If not, I would go back to the initial read data into SAS step and make sure that CPFN is character.
BTW, if the CPFN or other variable had leading zeroes then the read as numeric lost those. Which means that values in the original source such as "000123" and "0000000000123" would both now be numeric 123 and likely wrong for some purposes.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.