BookmarkSubscribeRSS Feed
osho
Calcite | Level 5
I have a field called customer_id which has field type=character but It has 90,000 numbers and about 100 names.

When I convert the field type from character to numeric, it stumbles on the 100 names since they cannot be converted to numeric. I do not care about these names and want to remove them so only numbers will be retained.

Code
-------
data temp (keep = customer_skey customer_id) ;
set fdw.customer;
customer_id_new=input(customer_id, 8.);
run;

Error message :
------------------


Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.

The problem is that it does NOT create the new field which is numeric, it just gives up. I would like the program to ignore these errors where the data are characters

OR

I would like to remove the character data so the remaining numbers can easily converted to numeric data types.


Is there a way to purge out all character data from a field and keep only numeric, so the datatype can be converted from character to numeric?
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You can explore using the DATA step function and logic such as:

IF ANYALPHA() = 0 THEN ;

For observations with non-numeric values, you will have a SAS MISSING value condition.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
You can eliminate these warnings/errors by using:

if input(customer_id, ?? best.) ne . then customer_id_new=input(customer_id, 8.);

~ Sukanya E
jf
Fluorite | Level 6 jf
Fluorite | Level 6
data temp2 ;
set temp;
customer_id_new ^= .;
run;
advoss
Quartz | Level 8
Or,
data temp (keep = customer_skey customer_id) ;
set fdw.customer;
if missing(input(customer_id, ??8.)) then delete;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1571 views
  • 0 likes
  • 5 in conversation