- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 06-09-2023 04:18 PM
(2557 views)
How do i remove leading zeros for a variable with values that look like this:
00099V67
000123
Some have two zeros in front some have three.
00099V67
000123
Some have two zeros in front some have three.
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You apparently have a character variable, since one of your sample values has the letter "V" in it.
First, and definitely foremost: why do you want to remove leading zeroes from a non-numeric variable?
Let's say you did so. Then, since your sort order is lexicographic, instead of sort order of
000999
002231
011577
with leading zeroes removed (and the remaining characters left-justified) you would have this order:
11577
2231
999
Do you really want that
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This has been asked before, you could search and see if you can find the older discussions.
This is what the VERIFY function is good at.
data have;
input str $12.;
cards;
00099V67
000123
12345
;
data want;
set have;
if verify(trim(str),'0') then str=substr(str,verify(str,'0'));
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What does your variable represent? Leading zeroes can have meaning in character variables and could be dangerous to remove.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input str $12.;
cards;
00099V67
000123
12345
;
data want;
set have;
want=prxchange('s/^0+//',1,strip(str));
run;