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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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. 

jerry898969
Pyrite | Level 9

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. 

Astounding
PROC Star

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.

Tom
Super User Tom
Super User

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.

Tom
Super User Tom
Super User

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.

jerry898969
Pyrite | Level 9

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

Tom
Super User Tom
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 33305 views
  • 3 likes
  • 4 in conversation