DATA Step, Macro, Functions and more

limit all numberic variables with 2 decimals

Accepted Solution Solved
Reply
Super Contributor
Posts: 318
Accepted Solution

limit all numberic variables with 2 decimals

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.


Accepted Solutions
Solution
‎04-26-2016 12:30 PM
Super User
Posts: 19,771

Re: limit all numberic variables with 2 decimals

Posted in reply to fengyuwuzu

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


All Replies
Solution
‎04-26-2016 12:30 PM
Super User
Posts: 19,771

Re: limit all numberic variables with 2 decimals

Posted in reply to fengyuwuzu

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. 

Respected Advisor
Posts: 3,799

Re: limit all numberic variables with 2 decimals

Posted in reply to fengyuwuzu

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

Super Contributor
Posts: 318

Re: limit all numberic variables with 2 decimals

Posted in reply to data_null__
yes, the W in W.2
Respected Advisor
Posts: 3,799

Re: limit all numberic variables with 2 decimals

Posted in reply to fengyuwuzu

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.

Super Contributor
Posts: 318

Re: limit all numberic variables with 2 decimals

Posted in reply to data_null__

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

 

Super User
Super User
Posts: 7,942

Re: limit all numberic variables with 2 decimals

Posted in reply to fengyuwuzu

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.

 

Super Contributor
Posts: 318

Re: limit all numberic variables with 2 decimals

actually I meant formatting, just for display
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 308 views
  • 0 likes
  • 4 in conversation