Help using Base SAS procedures

delete within bracket ()

Reply
Super Contributor
Posts: 395

delete within bracket ()

Hi, I'm trying to delete data that's within a bracket but keep the rest. 

Have:

NAME

Sammy (NL)

Don (DP)

Greg (OL)

Fred Donalson (DE)

St. George B (BW)

Want:

NAME

Sammy

Don

Greg

Fred Donaldson

St. George B

I tried this :

do i=1 to count (NAME,'(');

NAME2 = scan(NAME,i);

output;

end;

PROC Star
Posts: 7,363

delete within bracket ()

There are a number of ways.  If you only have the one set of parentheses in each string, probably the easiest would be a slight modification of what you tried:

data have;

  informat name $30.;

  input name &;

  cards;

Sammy (NL)

Don (DP)

Greg (OL)

Fred Donalson (DE)

St. George B (BW)

;

data want;

  set have;

  name=scan(name,-2,'(');

run;

Super Contributor
Posts: 1,636

delete within bracket ()

another way:

data have;

  informat name $30.;

  input name &;

  cards;

Sammy (NL)

Don (DP)

Greg (OL)

Fred Donalson (DE)

St. George B (BW)

;

data want;

    set have;

  name=substr(name,1,find(name,'(')-1);

run;

proc print;

run;

Super User
Posts: 9,681

delete within bracket ()

data have;
  informat name $30.;
  input name &;
  cards;
Sammy (NL)
Don (DP)
Greg (OL)
Fred Donalson (DE)
St. George B (BW)
;
run;
data want;
 set have;
 a=prxchange('s/\(\w+\)/ /',-1,name);
run;

Ksharp

Ask a Question
Discussion stats
  • 3 replies
  • 136 views
  • 0 likes
  • 4 in conversation