- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 01-29-2010 02:58 PM
(1307 views)
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Scott Barry
SBBWorks, Inc.
Recommended Google advanced search argument for this topic/post:
convert number character remove leading zeros site:sas.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 ' '
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 ' '
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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]
[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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for all your sample codes. The issue solved.
Regards
David
Regards
David