Hello,
I would like to remove all the numeric but keep one space between the text as I show in the result column. Please help. Thank you.
data datain9;
infile datalines dsd;
input Name : $300. Result : $ 100. ;
datalines;
Car_ID_6666, Car ID,
Home_000_9463_Address, Home Address,
30890_Zip_Code, Zip Code,
;
run;
Your best bet is probably a combination of functions. I chose COMPRESS to get rid of your digits, TRANSLATE to turn your underscores into spaces, COMPBL to take care of any interior spaces that were longer than a single blank, and STRIP to make sure there weren't any leading (or trailing) spaces hanging around. Other combinations of functions will certainly work, but this allows you to use a single function to target each of the issues you're facing.
data have;
input Name : $300.;
cards;
Car_ID_6666
Home_000_9463_Address
30890_Zip_Code
;
run;
data want;
set have;
Result = strip(compbl((translate(compress(name,,'d'),' ','_'))));
run;
data datain9;
infile datalines dsd;
input Name : $300. Result : $ 100. ;
datalines;
Car_ID_6666, Car ID,
Home_000_9463_Address, Home Address,
30890_Zip_Code, Zip Code,
;
run;
data want;
set datain9;
want=compbl(translate(compress(name,,'d'),' ','_'));
run;
Your best bet is probably a combination of functions. I chose COMPRESS to get rid of your digits, TRANSLATE to turn your underscores into spaces, COMPBL to take care of any interior spaces that were longer than a single blank, and STRIP to make sure there weren't any leading (or trailing) spaces hanging around. Other combinations of functions will certainly work, but this allows you to use a single function to target each of the issues you're facing.
data have;
input Name : $300.;
cards;
Car_ID_6666
Home_000_9463_Address
30890_Zip_Code
;
run;
data want;
set have;
Result = strip(compbl((translate(compress(name,,'d'),' ','_'))));
run;
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!
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.