Hi ,
How to remove the leading and traling spacce inside brackets.
My data is below.
data have;
input_var $200;
cards;
( 12.5)
( 1.5)
(111.9)
( 2.8)
( 20.0)
;
run;
Thank you,
Rajasekhar.
data have; input var $char80.; cards; 234 ( 23.5) 0 12 ( 34) 30 ( 12.5) 34 ( 0.5 ) ; data want; set have; new_var=prxchange('s/\(\s*([\d\.,]+)?\s*\)/(\1)/',-1,var); run;
Hi ,
Thank you for response.
I am wrongly post the data , i need to remove the space in side the bracket only.
data have;
infile datalines truncover;
input_var $200;
234 ( 23.5)
0
12 ( 34)
30 ( 12.5)
34 ( 0.5 )
;
run;
@raja777pharma wrote:
Hi ,
Thank you for response.
I am wrongly post the data , i need to remove the space in side the bracket only.
data have;
infile datalines truncover;
input_var $200;
234 ( 23.5)
0
12 ( 34)
30 ( 12.5)
34 ( 0.5 )
;
run;
That data step still does not run. Incorrect statement: input _var NOT input_var
The Informat should end a dot: $200.
If the strings only have the one parenthetical value then I would just rebuild it.
data have;
input var $char80.;
cards;
234 ( 23.5)
0
12 ( 34)
30 ( 12.5)
34 ( 0.5 )
;
data want;
set have;
new_var=var;
if index(var,'(') then
new_var = substrn(var,1,index(var,'('))
||compress(substrn(var,index(var,'(')+1))
;
put (var new_var) (:$quote./) /;
run;
Results:
"234 ( 23.5)" "234 (23.5)" " 0" " 0" " 12 ( 34)" " 12 (34)" " 30 ( 12.5)" " 30 (12.5)" " 34 ( 0.5 )" " 34 (0.5)"
PS: Your British is showing. The characters used to include parentheticals are called parentheses. Brackets look like this: [ ].
You should show what you expect the result to be so can have a chance of seeing if our suggestions do as desired.
Also, please run your data step and make sure it creates the desired data. Yours has issues as posted.
This is my attempt.
data have; infile datalines truncover; input _var $200. ; _var = compress(_var,' '); cards; ( 12.5) ( 1.5) (111.9) ( 2.8) ( 20.0) ;
The Truncover is because you are requesting reading so many characters with the $200. informat (incorrectly specified in your code) that SAS will attempt to read from following lines and only gets a couple of records, AFTER fixing the informat and incorrect INPUT statement.
Compress function removes characters.
data have; input var $char80.; cards; 234 ( 23.5) 0 12 ( 34) 30 ( 12.5) 34 ( 0.5 ) ; data want; set have; new_var=prxchange('s/\(\s*([\d\.,]+)?\s*\)/(\1)/',-1,var); run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.