BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JavierBlanco
Calcite | Level 5

I need to remove some initial zeros from a field (it appears as an alphanumeric one in the DB) like this:

 

cod_acometida
000000000003391901
000000000008271401
000000000007696901
000000000005504701
000000000002298401
000000000000332701
000000000013942801
etc.

 

It's a variable number of characters but they are always zeros at the beginning of the string. I'm new at SAS, not sure if RegEx is applicable.

 

I'm using Enterprise Guide 7.15.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

You can use the exact same expression in a Proc SQL Step. If you want to use the value without zeros in a join, simply use the 

 

substr(cod_acometida, verify(cod_acometida, '0'))

part directly in the join. 

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input cod_acometida :$20.;
datalines;
000000000003391901
000000000008271401
000000000007696901
000000000005504701
000000000002298401
000000000000332701
000000000013942801
;

data want;
   set have;
   cod_acometida = substr(cod_acometida, verify(cod_acometida, '0'));
run;
JavierBlanco
Calcite | Level 5

Thanks for your answer, but cod_acometida has many rows, not just the few ones that I put as an example. I'm trying to handle it as a SQL query within a

 

PROC SQL;

***

QUIT;

Actually I need to use that cod_acometida (but 'zeroless') in a JOIN clause; it appears without zeros in the other table.

 

Thanks in advance.

PeterClemmensen
Tourmaline | Level 20

You can use the exact same expression in a Proc SQL Step. If you want to use the value without zeros in a join, simply use the 

 

substr(cod_acometida, verify(cod_acometida, '0'))

part directly in the join. 

Kurt_Bremser
Super User

The DATA step with DATALINES is just there to make usable example data (please remember this term and method, and use it to present example data in your future questions) out of the text you posted. It is not needed for your real data, which should already be in a SAS dataset.

 

Before you attempt the join, make sure that the variable types match, and see if you have leading blanks in the "other" dataset.

s_lassen
Meteorite | Level 14

@Kurt_Bremser :

The method suggested

cod_acometida = put(input(cod_acometida,32.),32. -l);

will work for the data shown, but if the string has more than 15 significant digits (it is, after all, 19 digits long) you may get rounding errors.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1396 views
  • 4 likes
  • 4 in conversation