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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 2 replies
  • 736 views
  • 2 likes
  • 3 in conversation