BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
confused_saser
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

3 REPLIES 3
Astounding
PROC Star

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.

confused_saser
Obsidian | Level 7

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

Tom
Super User Tom
Super User

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.

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!

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.

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
  • 3 replies
  • 1961 views
  • 2 likes
  • 3 in conversation