data test; num=1901012434.0000000; num1=put(num,10); run;
If you run this code it correctly ends where the period is displayed. 1901012434
However my dataset provides the entire number as a numeric value from the dataset.
1901012434.0000000 is what is shown.
1. I want to show just the first 10 numbers and
2. Convert it to a character value
data test;
num1 = 1901012434;
num2 = num1;
num3 = put(num1, 10.);
format num1 18.7;
format num2 10.;
run;
num1: Number shown with .0000000
num2: Number shown without .0000000
num3: Character variable without .0000000
@Q1983 wrote:
data test; num=1901012434.0000000; num1=put(num,10); run;If you run this code it correctly ends where the period is displayed. 1901012434
However my dataset provides the entire number as a numeric value from the dataset.
1901012434.0000000 is what is shown.
1. I want to show just the first 10 numbers and
2. Convert it to a character value
So does NOT have DECIMAL numbers. It only has binary floating point numbers. So 1901012434 , 1901012434.0000000 and 1,901,012,434 are all stored as the exact same binary floating value. If they are displayed differently then you must have attached a different display FORMAT to the variable. A FORMAT is instructions for how to display the value as text strings.
If you want to display the 10 digits then attach the 10. (or if you want leading zeros then Z10.) format to the variable.
If you want to convert it to a character string use the PUT() function with the format of your choice. Watch out for character values though because there are multiple ways to store the same number as a character string. In particular if the value is less than a billion then using 10. format will store leading spaces into the character string.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.