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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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