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
data have;
input var $10.;
cards;
QA-012
SAA-02223
UKV-049
S-01
;
data want;
set have;
new_var=tranwrd(var,'-0','-');
run;
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
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?
Dear friend
Goog question
I like to remove only "-0"
and not the other 0
best regards
Farshid
data have;
input var $10.;
cards;
QA-012
SAA-02223
UKV-049
S-01
;
data want;
set have;
new_var=tranwrd(var,'-0','-');
run;
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.