BookmarkSubscribeRSS Feed
podarum
Quartz | Level 8

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.

4 REPLIES 4
ballardw
Super User

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);

DBailey
Lapis Lazuli | Level 10

or you could convert it to numeric and back

Astounding
PROC Star

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

podarum
Quartz | Level 8

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.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 804 views
  • 3 likes
  • 4 in conversation