turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- limit all numberic variables with 2 decimals

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-26-2016 10:07 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-26-2016 10:27 AM

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.

All Replies

Solution

04-26-2016
12:30 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-26-2016 10:27 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-26-2016 10:37 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-26-2016 10:57 AM

yes, the W in W.2

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-26-2016 12:17 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-26-2016 12:30 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-26-2016 10:45 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-26-2016 10:56 AM

actually I meant formatting, just for display