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.);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.