Desktop productivity for business analysts and programmers

Decimal to Numeric conversion in SAS EG

Reply
New Contributor
Posts: 2

Decimal to Numeric conversion in SAS EG

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!

PROC Star
Posts: 1,146

Re: Decimal to Numeric conversion in SAS EG

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

Super User
Posts: 19,171

Re: Decimal to Numeric conversion in SAS EG


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?

Super User
Super User
Posts: 6,848

Re: Decimal to Numeric conversion in SAS EG

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.

 

New Contributor
Posts: 2

Re: Decimal to Numeric conversion in SAS EG

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!

Super User
Posts: 19,171

Re: Decimal to Numeric conversion in SAS EG


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.

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 230 views
  • 0 likes
  • 4 in conversation