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
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.
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.
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.
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.
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.
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.
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
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: