BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10
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

2 REPLIES 2
derekg
Obsidian | Level 7
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

Tom
Super User Tom
Super User

@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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 952 views
  • 0 likes
  • 3 in conversation