BookmarkSubscribeRSS Feed
gtucke1
Fluorite | Level 6

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

7 REPLIES 7
Reeza
Super User

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


 

gtucke1
Fluorite | Level 6

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.?

 

 

Reeza
Super User

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.

gtucke1
Fluorite | Level 6

Okay. Since it's a NOTE is the data okay to use?

pink_poodle
Barite | Level 11

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.

Reeza
Super User

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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 7 replies
  • 739 views
  • 3 likes
  • 4 in conversation