BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I need to have the 'test'value without the charaters in parenthesis. I am using scan function. Is there any better way to get the output. Please suggest. Thank you

 

Output needed:

term1

Urine Choriogonadotropin Beta

 

data one;
input test $ 1-35;
datalines;
Urine Choriogonadotropin Beta (NA)
;
run;
data two;
set one;
term1=scan(test,1,'(');
run;
3 REPLIES 3
novinosrin
Tourmaline | Level 20

Assuming the characters in paranthesis is at the end of the string in all records if present.

 

data one;

input test $ 1-35;

datalines;

Urine Choriogonadotropin Beta (NA)

;

run;

 

data two;

set one;

substr(test,index(test,'('))=' ';

run;

 

Regards,

Naveen Srinivasan

Patrick
Opal | Level 21

Or if you need to remove all brackets no matter where they are in the string:

data one;
  input test $ 1-70;
  datalines;
Urine Choriogonadotropin Beta (NA)
Urine Choriogonadotropin Beta (NA) something (something else)
;
run;

data two;
  set one;
  /* create variable term1 with the same length as test */
  if _n_=1 then term1=test;
  /* remove everything in brackets from source string */
  term1=prxchange('s/\s*\([^\)]*\)//o',-1,strip(test));
run;
art297
Opal | Level 21

You can do it in one data step. e.g.:

 

data one;
  length test $50;
  input @;
  if index(_infile_,'(') gt 0 then
   _infile_=substr(_infile_,1,index(_infile_,'(')-1);
  input test &;
datalines;
Urine Choriogonadotropin Beta (NA)
Urine Choriogonadotropin Alpha
;

Art, CEO, AnalystFinder.com

 

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
  • 3 replies
  • 1784 views
  • 3 likes
  • 4 in conversation