The variables cg_edu and cg_age were entered as character values. I need to change them to numeric values. Below is the code I used with the error message. How do I resolve this problem? Do I have to go into the dataset and change something?
cg_edu_numeric = cg_edu + 0;
cg_age_numeric = cg_age + 0;
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
2720:15
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
9 at 2720:19
You're using what's called implicit conversion, where SAS will assume you want numbers and convert it and warn you about it. Use explicit conversion to avoid the warnings.
cg_edu_numeric = input(cg_edu, 8.);
@gtucke1 wrote:
The variables cg_edu and cg_age were entered as character values. I need to change them to numeric values. Below is the code I used with the error message. How do I resolve this problem? Do I have to go into the dataset and change something?
cg_edu_numeric = cg_edu + 0;
cg_age_numeric = cg_age + 0;
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
2720:15
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
9 at 2720:19
Thank you for the information. I forgot to mention that age and education are in years. Does this change anything in the code you suggested? How did to come to use 8.?
8. is the informat, which is telling SAS what format it currently is in and how to read the data in.
It is used for numeric values, years will be fine for 8.
Your informat should match how your data appears as text.
This is not an ERROR, it's a NOTE informing you of the automatic conversion, and that there were 9 missing values.
Okay. Since it's a NOTE is the data okay to use?
Are you sure there was no mixed values there that got converted to missing? For example, if someone entered age “5A”, but then that is probably a good thing unless you wish to clean it to something like 5 if you are completely certain that the age is 5. I think both methods, implicit and explicit, would convert age “5A” to missing numeric age.
Only you can know that.
A quick way to check it is to run a frequency of the new against old data though and see if anything looks weird. I would highly recommend using the INPUT() function to convert your data.
proc freq data=dataSetName;
table cg_edu_numeric*cg_edu / MISSING;
table cg_age_numeric*cg_age / MISSING;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.