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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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