BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have variable in which I am getting a value four places after decimals.
I want that value to be 2 places after decimals.

for example:
a variable v1=0.1234
but i want the variable value to be only 0.12

Is there any function in sas which I can use to achieve this?
3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12
The ROUND function may do what you want. CEIL, FLOOR, and INT are also possibilities; check SAS documentaiton for the differences.

If you just want the display to be 2 digits after the decimal, then you can apply a format to the variable.

Some statistical procedures, like PROC MEANS, sometimes give more decimals than desired. The only way to force the format is to output the summary statisticis into a dataset and apply a format for printing.
Cynthia_sas
Diamond | Level 26
The other approach, depending on the procedure that's producing the number is to alter the table template used for the procedure, as described in this Tech Support FAQ: http://support.sas.com/ctx/samples/index.jsp?sid=285&tab=details

Although the FAQ discusses PROC FREQ, the techniques are translatable to any procedure that has a table template. To determine the name of the table template that you must change, you would have to use ODS TRACE to find the template name for your output object of interest.

cynthia
deleted_user
Not applicable
@ Doc@Duke:

With Proc Means you could also use the option MAXDEC = 2.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1364 views
  • 0 likes
  • 3 in conversation