DATA Step, Macro, Functions and more

How two remove 0 from first position

Reply
Occasional Learner
Posts: 1

How two remove 0 from first position

I have three columns were the data should be in 2 or three figures but the should not start with a 0, but i have a few values where the figure is of 2 digits but with a zero for example :

DIBP

82
86
85
084
85
86
083


How do i remove the zero's
Super Contributor
Posts: 341

Re: How two remove 0 from first position

Are those columns of a SAS dataset ?

If so, does this mean that values are stored as character variables ?

Why not use a numeric format since your data is of numeric nature ?

 

Super User
Super User
Posts: 8,127

Re: How two remove 0 from first position

Use SUBSTR() function.  Either start from the 1st or the 2nd character depending on whether it starts with zero or not.

DIBP=substr(DIBP,1+DIBP=:'0');
Super User
Posts: 10,787

Re: How two remove 0 from first position

data have;
input DIBP $;
want=prxchange('s/^0+//',1,dibp);
cards;
82
86
85
084
85
86
083
;
run;
Super User
Posts: 23,778

Re: How two remove 0 from first position

I'm with @gamotte, the type of your data is more important. Numeric variables do not have a leading 0 by default, so I'm guessing it's character. If that's the case and you want to do any math with these values you'll also need a type conversion and if you're doing that you can avoid dealing with the leading 0 at all.
Ask a Question
Discussion stats
  • 4 replies
  • 57 views
  • 0 likes
  • 5 in conversation