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

Any help to remove 00 from the records below via proc sql? I want to display blanks if the records has multiple 00s without any alphabets

 

00,CQ,GC
00,RT,00,IR
00,00
RT,GT,KL
100,1000,00,RT

Excepted Result:

 

CQ,GC
RT,IR

RT,GT,KL
100,1000,RT
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

I believe for your sample data the 2nd expression from the OR condition @FreelanceReinh proposes is sufficient. Because you wrote MULTIPLE and not EXACTLY TWO zeros I've also added a + (one or many) after the second zero.

select prxchange('s/\b00+\b,?//',-1,trim(c)) as c length=60

 

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @Babloo,

 

Start with the Perl regular expression below ...

data have;
input c $char60.;
cards;
00,CQ,GC
00,RT,00,IR
00,00
RT,GT,KL
100,1000,00,RT
;

proc sql;
create table want as
select prxchange('s/,00\b|\b00\b,?//',-1,c) as c length=60
from have;
quit;

... and then modify it if necessary, e.g., to include space characters:

select prxchange('s/,\s*00\b\s*|\s*\b00\b,?\s*//',-1,c) as c length=60
Patrick
Opal | Level 21

I believe for your sample data the 2nd expression from the OR condition @FreelanceReinh proposes is sufficient. Because you wrote MULTIPLE and not EXACTLY TWO zeros I've also added a + (one or many) after the second zero.

select prxchange('s/\b00+\b,?//',-1,trim(c)) as c length=60

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2 replies
  • 1456 views
  • 3 likes
  • 3 in conversation