BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Duggins
Obsidian | Level 7

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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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;
Duggins
Obsidian | Level 7

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;
How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1757 views
  • 2 likes
  • 3 in conversation