turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- deleting the first leading digit but in certain ca...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-20-2014 03:53 PM

Hi, I have a field with accounts that most (80%) have a 0 on the left side.. eg. 081513105 .. I would like to get rid of this leading 0, but only for the accounts that are 9 digits in length and only if the leading is a 0.. if not 0 or less/more than 9 digits in length to leave as is... Any easy way to do this ? Thank you.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-20-2014 04:20 PM

Assuming this is actually a character value...

in a datastep something like this with your variable should work

if length (variable)=9 and substr(variable,1,1)='0' then variable = substr(variable,2);

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-20-2014 04:22 PM

or you could convert it to numeric and back

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-20-2014 04:33 PM

What if it is 9 digits long and starrts with 2 zeros? What if it is 10 digits long and starts with 2 zeros?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-21-2014 10:21 AM

Thanks all, all valid questions and points. But for my "small" enough data, ballardw's solution works well.. But totally agree if the data was larger and a whoel mix of scenarios.