BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14
Spoiler
Spoiler
 

Hello

I am trying to learn the topic of convert char to numeric.

I know the formula: Numeric=INPUT(char, informat);

My problem is that sometimes it is difficult for me to recognize the in informat.

For example:

convert char value   123,456.78   to   numeric.

I saw that the solution is Numeric=INPUT(char, COMMA12.);

Numeric value returned 123456.78   

My question is why the informat is COMMA12.? 

I see that there are 2 numbers after the point and 6 numbers before the point.

I was sure that the informat should be comma6.2  because there are 6 numbers in left of point and 2 in right of point

For example:

There are 2 records under char variable :   82.04   and 108498.19

I would like to convert these values into numeric

I saw that there are multiple solutions.

Numeric=INPUT(char, COMMA10.2);

Numeric=INPUT(char, COMMA32.);

Numeric=INPUT(char, COMMA15.);

My question is why there are multiple informats that can be used in this case???

Is there not only one correct informat?

I also want to understand please what is the correct informat in this example

 

Thanks in advance

Joe

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User
If you use BEST32 as an INformat it is just a alias for the normal 32. informat.

View solution in original post

8 REPLIES 8
data_null__
Jade | Level 19
d
specifies the powerof 10 by which to divide the value. If the data contain decimal points,the d value is ignored. This argument is optional. 
Ronein
Meteorite | Level 14
I don't understand. Can you try to explain it again please?
char value 123,456.78 has decimal point.
what should be the informat?
Is it possible that there are multiple informats that can be used in this example?
Ronein
Meteorite | Level 14
Is it possible to use informat BEST32. for any case????
When will we use informat BEST32. ?
Tom
Super User Tom
Super User
If you use BEST32 as an INformat it is just a alias for the normal 32. informat.
Tom
Super User Tom
Super User

@Ronein wrote:
I don't understand. Can you try to explain it again please?
char value 123,456.78 has decimal point.
what should be the informat?
Is it possible that there are multiple informats that can be used in this example?

Only include a number of decimal places on the INFORMAT if you want SAS to imply where the decimal point should be when the string being read does NOT contain one.  So with 32.2 as the INFORMAT the string '1234567' will become the number 12,345.67.  But if the string has a decimal point the number of decimal places listed in the informat is ignored.  So a string like '1234.567' becomes the number 1,234.567

Tom
Super User Tom
Super User
COMMA32 in some ways is the "best" informat. It will ignore commas and dollar signs. But note that means it is happy to convert strings like '12,34,56$78' that a human would consider invalid to the number 12,345,678.
Ronein
Meteorite | Level 14

Thank you.

In char value 108498.19  there are 2 number after decimal point.

What is the correct informat here?

Is it important to see how many number in right side of decimal point?

Can you explain please. I still not understand

Tom
Super User Tom
Super User
You do not have to tell SAS how to recognize the decimal point. Just use a width that is long enough not to ignore the last three characters.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 985 views
  • 0 likes
  • 3 in conversation