BookmarkSubscribeRSS Feed
ramya4
Fluorite | Level 6

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!

5 REPLIES 5
TomKari
Onyx | Level 15

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

Reeza
Super User

@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?

Tom
Super User Tom
Super User

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.

 

ramya4
Fluorite | Level 6

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!

Reeza
Super User

@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.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 6706 views
  • 0 likes
  • 4 in conversation