BookmarkSubscribeRSS Feed
Kwok
Calcite | Level 5
Hi,

Is there any SAS function that will remove all leading zeop from a string ? I check all the CAT(x) functions but non of them deal with leading zero alone.

Thanks
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The presumption here is that you are dealing with a SAS CHARACTER variable - one that has zero character(s) as part of the string? If so, look at using the combination of an INPUT function invocation (to convert the number char-string to a SAS NUMERIC variable, and then using the PUT function in an assignment statement to convert back to character -- add the -l operand as part of the PUT function's second argument to left-justify, if desired.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search argument for this topic/post:

convert number character remove leading zeros site:sas.com
RickM
Fluorite | Level 6
maybe

x=translate(left(translate(x,' 0','0 ')),' 0','0 ');

this should switch 0's and ' ', take off the leading blanks and switch back any 0's and ' '
data_null__
Jade | Level 19
An alternative using the "new" SUBSTRN function.

[pre]
99 data _null_;
100 input s:$20.;
101 z = substrn(s,verify(s,'0'));
102 put 'NOTE: '(_all_)(=);
103 cards;

NOTE: s=000ABC z=ABC
NOTE: s=00aa z=aa
NOTE: s=001 z=1
NOTE: s=100 z=100
NOTE: s=Help z=Help
[/pre]
Kwok
Calcite | Level 5
Thanks for all your sample codes. The issue solved.

Regards
David

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

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
  • 4 replies
  • 1592 views
  • 0 likes
  • 4 in conversation