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?
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.
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.
Oh man that was so easy! Thanks so much!!
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.