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

I am looking for a way to remove any 0s in a character string. I've found many threads about removing *leading* zeros, but not about removing 0s in general. For example:

 

Data I have:

AB001234

C01403

D00003456

 

Data I want:

AB1234

C143

D3456

 

Any ideas?

Thank you in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
COMPRESS function allows you to specify it.

want = compress(word, '0');

View solution in original post

3 REPLIES 3
Reeza
Super User
COMPRESS function allows you to specify it.

want = compress(word, '0');
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
Data have;
input string $25.;
cards;
AB001234
C01403
D00003456
;
 
Data  want;
set have;
new_string = COMPRESS (string,0 );
run;
novinosrin
Tourmaline | Level 20

Hi @VDD  You are missing quotes around the 0. This will unnecessarily make SAS write a note to the log about the auto conversion. Just watch out for that

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
  • 3 replies
  • 770 views
  • 4 likes
  • 4 in conversation