BookmarkSubscribeRSS Feed
Shrij
Calcite | Level 5
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
4 REPLIES 4
gamotte
Rhodochrosite | Level 12

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 ?

 

Tom
Super User Tom
Super User

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');
Ksharp
Super User
data have;
input DIBP $;
want=prxchange('s/^0+//',1,dibp);
cards;
82
86
85
084
85
86
083
;
run;
Reeza
Super User
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 661 views
  • 0 likes
  • 5 in conversation