Hello,
I am trying to convert an amount field from character to numeric using input function but unable to do.
Getting error Invalid argument to input function.
I have tried commaw.d , bestw.d informats as well but its not working.
amount=input(amount_old,20.2);
example: data in amount_old field
23.45
12,300.56
123,123.23
Thanks in advance.
Not sure what you have been doing, but this seems to work fine:
data have;
length amount_old $20;
input amount_old;
amount=input(amount_old,comma20.2);
cards;
23.45
12,300.56
123,123.23
;run;
The dollar. informat is the most flexible one. It handles commas, dollar signs and plain numbers.
Thank you.
I can able to convert from char to numeric while creating dataset using datalines.
I have pipe delimited file in which trying to process the data but its not happening.
data one;
infile "filename" delimiter='|' missover dsd lrecl=2000;
informat amount comma26.2;
length amount 8;
input amount;
run;
error: Invalid data for amount
for the above, if I am keeping amount column as character I can able to create the dataset without any errors. once the dataset creates, trying to convert amount field from char to numeric, getting error invalid argument to input function.
@ChrisNZ wrote:
The dollar. informat is the most flexible one. It handles commas, dollar signs and plain numbers.
The DOLLAR informat is just an alias for the COMMA informat.
Did you really intend to divide the integer values by 100? If not then do NOT include a decimal part in the INFORMAT. The purpose of the decimal part of an informat is to tell SAS that the decimal point is explicitly NOT present in the data to save one character in representing the number as text. The maximum width that the COMMA informat supports is 32 and the INPUT() function does not mind if the width you use on the informat is larger than the length of the string you are reading.
amount=input(amount_old,comma32.);
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.