Hi All,
Happy New Year!!
I am trying to convert character to numeric for one of the variable, it is in numeric in CSV but when imported to SAS, it became character variable. E.g.
Name Area_code race
xyz 6213 White
abc 5234 Asian
dcg White
Area_Code is a character in SAS. I used input to convert to numeric
area=input(code, best12.);
I am getting a "NOTE: Invalid argument to function INPUT at line 744 column 23" in the log but the variable was converted to numeric. My question is why I'm still getting this NOTE in the log and is there anything that I'm doing wrong?
Thank you,
M
Generally, there's no advantage or disadvantage to having area code as numeric, so the effort to change it to numeric doesn't really provide benefit. So why do you need area code as numeric?
Obviously, you have a blank value in one row. When SAS tries to do the conversion, it cannot translate the blank value into a meaningful numeric value. Still, it is just a missing value, and should be interpreted as such. One possibility is simply suppressing the error message, using the ?? modifier for the input statement:
area=input(code,?? best12.);
The other possibility, which would still give you a message when a "rogue" value is encountered (something that is not a number or a blank) is to use the MISSING option:
options missing=' ';
and then proceed with the rest of your code. The blanks should then be interpreted as valid missing values. I assume that you are using PROC IMPORT for the first part; I am not sure how the procedure reacts to a change in the MISSING option, it is possible that you will get the variable numeric from the start if you put the OPTIONS statement before PROC IMPORT.
Thank you s_lassen for providing me with the options, but if I suppress the missing values and if I want to see the count for race then I won't be getting true count. And if I want to use area code as character and want to merge with other dataset that has area code as numeric then the merge will not work!
Regards,
M
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.