How do I solve this error when converting character to numeric?

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

How do I solve this error when converting character to numeric?

I am trying to convert a character variable to a numeric using the following code:

 

data mva_jasper4;
	set mva_jasper3;
	payorPrice_num = input(payorPrice, BEST32.);
run;

However I am getting multiple lines of this error:

NOTE: Invalid argument to function INPUT at line 10580 column 22.
MRN=4431155 name=Freda Snedden serv_date=10FEB2017 program=Auto Insurance Company - MVA
site=Ottawa description=IE | Homesite Assessment Code=IXXAC intake_flag=0 intake_form=0 block1=0
block2=0 block3=0 dc=0 migext=0 monitor=0 payorPrice=1,448.50 supp=0 payorPrice_num=. _ERROR_=1
_N_=38

I tried googling this but I don't think I understand what is actually wrong or how to solve this.

 

Can any suggest how I can fix this?


Accepted Solutions
Solution
‎07-14-2017 01:45 PM
Super User
Posts: 5,081

Re: How do I solve this error when converting character to numeric?

Notice the note in the log, which indicates that payorPrice contains a comma.  

 

SAS can't read a comma using the best. informat.  Try:

 

payorPrice_num = input(payorPrice, comma32.);

 

It's probably fine to use a smaller width if you need to, such as comma16. instead of comma32.

View solution in original post


All Replies
Solution
‎07-14-2017 01:45 PM
Super User
Posts: 5,081

Re: How do I solve this error when converting character to numeric?

Notice the note in the log, which indicates that payorPrice contains a comma.  

 

SAS can't read a comma using the best. informat.  Try:

 

payorPrice_num = input(payorPrice, comma32.);

 

It's probably fine to use a smaller width if you need to, such as comma16. instead of comma32.

Contributor
Posts: 37

Re: How do I solve this error when converting character to numeric?

Oh man that was so easy! Thanks so much!!

Super User
Super User
Posts: 6,499

Re: How do I solve this error when converting character to numeric?

[ Edited ]

Note that SAS does not have a "BEST" informat. If you do specify BEST32. then SAS will just use the normal 32. informat which can handle all of the various formats that the BEST format can generated.  (It will also handle scienfitic notation done using D instead of E to separated the value form the magnitude).  If you want to read values that can contain commas, dollar signs or parenthesis then you can use the COMMA informat (you can also call this the DOLLAR informat).  

 

So in many ways the COMMA informat is the "BEST" informat since it can read anything that the default informat can read plus it handles values with commas and dollar signs.

 

Note that if your values are using commas for decimal places and periods for thousands separators then you can use the COMMAX informat to reverse the meaning of those two characters.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 96 views
  • 2 likes
  • 3 in conversation