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

Showing results for

Find a Community

- Home
- /
- BI
- /
- Enterprise Guide
- /
- Decimal to Numeric conversion in SAS EG

Topic Options

- 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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-29-2017 05:04 PM

Hello,

How will I be able to convert decimal field to a numeric field in SAS EG?

For ex: I would like to convert 100.00 to 10000.

Any information would be much appreciated.

Thanks!

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

Posted in reply to ramya4

03-29-2017 05:46 PM

SAS only has two data types; numeric and character.

Your example is a bit confusing; you appear to be converting the number 100 to 10000.

Is that what you desire?

Tom

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

Posted in reply to ramya4

03-29-2017 06:15 PM

ramya4 wrote:

Hello,

How will I be able to convert decimal field to a numeric field in SAS EG?

For ex: I would like to convert 100.00 to 10000.

Any information would be much appreciated.

Thanks!

I suspect you read the data incorrectly in the first place. Perhaps fix at the source instead of after?

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

Posted in reply to ramya4

03-30-2017 12:55 PM

To change 100.00 to 10000 you just need to multiply by 100.

SAS only has one type for storing numbers.

What is it that prompted the question? One possibilty is the miss use of INFORMATs. With a SAS format you can specify the number of decimal places you want it to use by default when displaying your variable.

`attrib HEIGHT length=8 format=5.3 label='Height in meters';`

When reading data using INformats you can also specify a number of decimal places, but the meaning is completely different. On an INFORMAT the meaning of a non-zero specification of number of digits to the right of the decimal place is where should SAS assume the the decimal point is when there isn't one in the data. So if you were writng the above HEIGHT variable to a text file you could save one bytes per value by not wrting the decimal point. So 1.567 would be written as '1567'. You could then read that using the informat 4.3 and it would convert '1567' to the number 1.567. Note that if there is a decimal point in the string then the implied decimal point is not added. So '13.3' would be read as 13.3 and not as 1.33 or something else.

So if you read the string '10000' using the informat 6.2 it would generate the number 100.00 instead of the number 10,000.

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

03-30-2017 02:47 PM

Thanks all for providing the inputs. I figured out the function for doing that. I basically wanted to remove decimal point in the number and write the number as a whole number in the output.

Ex: If I am reading the number as 100.00, I wanted to write it as 10000. We could actually do that using the COMPRESS function in SAS EG.

COMPRESS(&STR,10.2),'.'

Thanks!

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

Posted in reply to ramya4

03-30-2017 03:04 PM

ramya4 wrote:

Thanks all for providing the inputs. I figured out the function for doing that. I basically wanted to remove decimal point in the number and write the number as a whole number in the output.

Ex: If I am reading the number as 100.00, I wanted to write it as 10000. We could actually do that using the COMPRESS function in SAS EG.

COMPRESS(&STR,10.2),'.'

Thanks!

That's not a number then, it's a string and **that's not a valid or correct use of the COMPRESS function.** If it worked, it was entirely an accident.