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
- /
- SAS Procedures
- /
- changing from 0 decimal to 2 decimal places

- 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

06-11-2015 10:40 AM

Hello,

I have some data that I geocoded and now I have a tract column that is defined as numeric with length of 8.

The format is BEST12. and the Informat is 12.

I'm not sure why the format and informat use 12 when there are at most 6 digits in the values.

I need to change the data from 999999 to 9999.00.

I have tried this code

data x ;

set geo_out ;

format tract 7.2 ;

run ;

This works for some of the numbers but not all. For example

100 turned into 100.00

but 950200 stayed the same and doesn't have a decimal.

Thank you

Accepted Solutions

Solution

06-11-2015
11:55 AM

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

06-11-2015 11:55 AM

Are you allowed to change the data values? This combination might be the right one:

tract = tract/100;

format tract 7.2;

I'm assuming that your original post was wrong, and that 999999 should not print as 9999.00. Rather it should print as 9999.99. If it really should print as 9999.00 you would need to use:

tract = int(tract/100);

format tract 7.2;

It seems possible that this correction could have been earlier, when creating the original data set. Good luck.

All Replies

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

06-11-2015 10:48 AM

I think this is a misunderstanding of the formats. In your example, the code 7.2 indicates that the maximum length of the value is 7 characters, with two of them being decimal. Look at this a bit lke a string:

[] [] [] [] [] [] [] - these are your 7 boxes for data

1 0 0 . 0 0 - 100 fits fine here as there is room for the whole part and the .00

9 5 0 2 0 0. - As you can see here there is not width available for the .00

So you need to specify a format length which is you largest value (character length) + 1 for the decimal place + 2 for the additional 2 zeroes. So if you maximum value is 950200, that is 6, add the 1 and add the 2 = 9.2 should be your format.

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

06-11-2015 11:01 AM

Thank you both for your replies,

I have to apologizes for a mistake I made in my original post.

The 100 needs to be 1.00. I need to take the value and put a decimal point so there are 2 digits after the decimal place.

950200 should be 9502.00

I don't need to add the extra .00 at the end it is part of the original value.

I'm sorry for the mistake.

Solution

06-11-2015
11:55 AM

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

06-11-2015 11:55 AM

Are you allowed to change the data values? This combination might be the right one:

tract = tract/100;

format tract 7.2;

I'm assuming that your original post was wrong, and that 999999 should not print as 9999.00. Rather it should print as 9999.99. If it really should print as 9999.00 you would need to use:

tract = int(tract/100);

format tract 7.2;

It seems possible that this correction could have been earlier, when creating the original data set. Good luck.

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

06-11-2015 10:49 AM

You need to use a longer width. You have 6 digits to the left of the decimal so you will need to raise the width from 7 to at least 9 to allow for 6 places to the left, the decimal point and 2 places to the right.

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

06-11-2015 01:51 PM

If you want to divide by 100 then just divide by 100. But in that case 100 will become 1.00 and not 100.00.

Unless that is some information elsewhere that says what values should be divided by 100.

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

06-11-2015 02:28 PM

Hello,

I can't change the values. The values range from 100 to 985900. So I would need the results to be 1.00 and 9859.00. I have to go in 2 places from the right of the value and put a decimal. I think the divide by 100 will do it.

Taking this approach will the data change?

Thank you both for all your help

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

06-11-2015 06:20 PM

If you don't want to change the value then create a PICTURE format.

proc format;

picture myformat low-high='000009.99' (mult=1) ;

run;

data _null_;

input x;

put x 7.2 +1 x myformat. ;

cards;

100

567890

run;

100.00 1.00

567890 5678.90