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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.