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

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