BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
farshidowrang
Quartz | Level 8

Hello guys,

 

I have a question which looks very easy

 

I have special names which contain -0 like:

 

QA-012

SAA-02223

UKV-049

S-01

S-01002

AS-012076

And not the oter zeos

I like to remove the -0 to have names like:

 

QA-12

SAA-2223

UKV-49

S-1

S-1002

AS-12076

 

Can you please help me with it?

 

Thank you very much in advance!

 

Best regards

 

Farshid 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
input var $10.;
cards;
QA-012
SAA-02223
UKV-049
S-01
;

data want;
set have;
new_var=tranwrd(var,'-0','-');
run;

View solution in original post

5 REPLIES 5
Reeza
Super User

Look at the TRANSLATE() function.

 


@farshidowrang wrote:

Hello guys,

 

I have a question which looks very easy

 

I have special names which contain -0 like:

 

QA-012

SAA-02223

UKV-049

S-01

 

I like to remove the 0 to have names like:

 

QA-12

SAA-2223

UKV-49

S-1

 

Can you please help me with it?

 

Thank you very much in advance!

 

Best regards

 

Farshid 

 

 


 

mkeintz
PROC Star

I suspect that the COMPRESS function is the way to go.  But do you want to eliminate ALL zeroes?,  I.e. do you want to eliminate these zeroes?

 

  ZZ-120

  AA-102

 

Or do you only want to eliminate leading zeroes in the component that follows the dash?

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
farshidowrang
Quartz | Level 8

Dear friend

 

Goog question

 

I like to remove only "-0"

 

and not the other 0

 

best regards

 

Farshid 

novinosrin
Tourmaline | Level 20
data have;
input var $10.;
cards;
QA-012
SAA-02223
UKV-049
S-01
;

data want;
set have;
new_var=tranwrd(var,'-0','-');
run;
Patrick
Opal | Level 21

Below some code which will remove any number of leading zeros after a dash but will always preserve the last digit (even if it's a zero).

data have;
  input var $10.;
  cards;
QA-012
SAA-00023
UKV-049
S-01
S-000
;

data want;
  set have;
  length new_var $10;
  new_var=prxchange('s/(-)0+(\d+)$/$1$2/oi',1,strip(var));
run;

proc print;
run;

Capture.JPG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 828 views
  • 5 likes
  • 5 in conversation