BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

I have the different numeric variable with different number of digits after the decimal. Is it possible to  convert them to same number of digits after decimal in one attempt by ROUNDING the digits, instead of applying the format each variable separately. Thank you

data orci;
 input effect$ a b c d e f;
 cards;
 points 1.05 1.055 1.0554 1.05545 1.055454 1.055455
;
run; 
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@SASuserlot wrote:

Is it possible to  convert them to same number of digits after decimal in one attempt by ROUNDING the digits, instead of applying the format each variable separately.


You could round the values one variable at a time, I don't see how that's any better than formatting each variable separately. And it really isn't that hard to format each variable in one line of code.

 

format a--f 10.2;

 

In fact, in my opinion, rounding the values is a poor decision, if there are additional calculations that will be performed on this data.

 

Which brings up the question ... why do you ask? What is the reason for either rounding them all or formatting them all?

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@SASuserlot wrote:

Is it possible to  convert them to same number of digits after decimal in one attempt by ROUNDING the digits, instead of applying the format each variable separately.


You could round the values one variable at a time, I don't see how that's any better than formatting each variable separately. And it really isn't that hard to format each variable in one line of code.

 

format a--f 10.2;

 

In fact, in my opinion, rounding the values is a poor decision, if there are additional calculations that will be performed on this data.

 

Which brings up the question ... why do you ask? What is the reason for either rounding them all or formatting them all?

--
Paige Miller
SASuserlot
Barite | Level 11

Thank you so much. Yes agree with you, in case if any additional calculations. In my case, these numbers at the end of all the calculations . Thanks again.

ballardw
Super User

ALL numeric variables use the list word _numeric_.

 

Format _numeric_  f8.1

 

Actual round isn't much harder:

data new;
   set old;
   array _nn (*) _numeric_;
   do i=1 to dim (_nn);
      _nn[i] = round(_nn[i], 0.1);
   end;
   drop i;
run;

make sure to pick an array name that doesn't duplicate that of an existing variable.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1030 views
  • 2 likes
  • 3 in conversation