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

Hi all,

 

First time posting, so apologies if I'm not doing this correctly.

 

I need to create reports where all the numbers are rounded to two decimal points. The code I have works, except for when the observation is a whole number. For example, 2.4378 will round to 2.44 like I want it to, but a flat 5 just shows up as 5. I would like it to show as 5.00 but am having trouble figuring out how to do so.

 

Here is one example:

data raw_deltas;
	set &dat._p_;

	%do i=1 %to &t;
		t&i = round(t&i, 0.01);
	%end;

	%do i=2 %to &t;
		delta&i = round(delta&i, 0.01);
		delta_&i = round(delta_&i, 0.01);
	%end;
run;

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Assign a format to the variable like F9.2  That will display the value as 9 characters including 2 decimals. Use a number larger than 9 if you need more positions. Generally any thing related to display of a single value can be resolved with a proper format.

 

Maybe

data raw_deltas;
	set &dat._p_;

	%do i=1 %to &t;
		t&i = round(t&i, 0.01);
	%end;

	%do i=2 %to &t;
		delta&i = round(delta&i, 0.01);
		delta_&i = round(delta_&i, 0.01);
	%end;
format t1-t&t. delta2-delta&t. delta_2-delta_&t. F9.2; run;

 

View solution in original post

2 REPLIES 2
ballardw
Super User

Assign a format to the variable like F9.2  That will display the value as 9 characters including 2 decimals. Use a number larger than 9 if you need more positions. Generally any thing related to display of a single value can be resolved with a proper format.

 

Maybe

data raw_deltas;
	set &dat._p_;

	%do i=1 %to &t;
		t&i = round(t&i, 0.01);
	%end;

	%do i=2 %to &t;
		delta&i = round(delta&i, 0.01);
		delta_&i = round(delta_&i, 0.01);
	%end;
format t1-t&t. delta2-delta&t. delta_2-delta_&t. F9.2; run;

 

nessak
Calcite | Level 5
thank you so much! that worked 🙂

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
  • 1833 views
  • 0 likes
  • 2 in conversation