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

Is there a way to change all the numeric variables in a data set to 2 decimals, without defining one by one? They have difference lengths, but I hope they all have max 2 decimals

 

thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Format _numeric_ 8.2;

 

The keyword is _numeric_ which applies to all numeric variables. But be careful, dates and ID variables can be numeric as well. 

View solution in original post

7 REPLIES 7
Reeza
Super User

Format _numeric_ 8.2;

 

The keyword is _numeric_ which applies to all numeric variables. But be careful, dates and ID variables can be numeric as well. 

data_null__
Jade | Level 19

What do you mean they "they have different lengths"?  Are you talking about the W in W.D as in 10 and 8 in 10.2, 8.2 etc.?

fengyuwuzu
Pyrite | Level 9
yes, the W in W.2
data_null__
Jade | Level 19

Sample data with working program to read and format as it is now would be helpful.  Plus an example data set of the result you desire.

 

@Reeza suggested the easy solution just format all the variable with W.2 where W is big enough for all values.

 

You're still a bit light on the details.

fengyuwuzu
Pyrite | Level 9

Thank you. I agree with you. I just need to choose a large enough W.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

By Change, do you mean just format the output to look like it has 2 decimal places, or change the underlying value to have only two decimal places, then you would need the round() function.

 

fengyuwuzu
Pyrite | Level 9
actually I meant formatting, just for display

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 7 replies
  • 2601 views
  • 0 likes
  • 4 in conversation