<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to remove leading and traling space inside brackets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796643#M255663</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/309000"&gt;@raja777pharma&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;Thank you for response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am wrongly post the data , i need to remove the space in side the bracket only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;infile datalines truncover;&lt;/P&gt;
&lt;P&gt;input_var $200;&lt;/P&gt;
&lt;P&gt;234&amp;nbsp; (&amp;nbsp; 23.5)&lt;/P&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;P&gt;12&amp;nbsp; &amp;nbsp;(&amp;nbsp; &amp;nbsp;34)&lt;/P&gt;
&lt;P&gt;30 ( 12.5)&lt;/P&gt;
&lt;P&gt;34&amp;nbsp; ( 0.5 )&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That data step still does not run. Incorrect statement: input _var&amp;nbsp; NOT input_var&lt;/P&gt;
&lt;P&gt;The Informat should end a dot: $200.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Feb 2022 17:29:04 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-02-16T17:29:04Z</dc:date>
    <item>
      <title>how to remove leading and traling space inside brackets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796611#M255640</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to remove the leading and traling spacce inside brackets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input_var $200;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;( 12.5)&lt;/P&gt;&lt;P&gt;(&amp;nbsp; &amp;nbsp;1.5)&lt;/P&gt;&lt;P&gt;(111.9)&lt;/P&gt;&lt;P&gt;(&amp;nbsp; 2.8)&lt;/P&gt;&lt;P&gt;( 20.0)&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Rajasekhar.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 16:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796611#M255640</guid>
      <dc:creator>raja777pharma</dc:creator>
      <dc:date>2022-02-16T16:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove leading and traling space inside brackets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796619#M255644</link>
      <description>new_var = compress(var);</description>
      <pubDate>Wed, 16 Feb 2022 16:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796619#M255644</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2022-02-16T16:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove leading and traling space inside brackets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796620#M255645</link>
      <description>&lt;P&gt;You should show what you expect the result to be so can have a chance of seeing if our suggestions do as desired.&lt;/P&gt;
&lt;P&gt;Also, please run your data step and make sure it creates the desired data. Yours has issues as posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my attempt.&lt;/P&gt;
&lt;PRE&gt;data have;
infile datalines truncover;
input _var $200. ;
_var = compress(_var,' ');
cards;
( 12.5)
(   1.5)
(111.9)
(  2.8)
( 20.0)
;&lt;/PRE&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compress function removes characters.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 16:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796620#M255645</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-16T16:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove leading and traling space inside brackets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796621#M255646</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;Thank you for response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wrongly post the data , i need to remove the space in side the bracket only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;infile datalines truncover;&lt;/P&gt;&lt;P&gt;input_var $200;&lt;/P&gt;&lt;P&gt;234&amp;nbsp; (&amp;nbsp; 23.5)&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp;(&amp;nbsp; &amp;nbsp;34)&lt;/P&gt;&lt;P&gt;30 ( 12.5)&lt;/P&gt;&lt;P&gt;34&amp;nbsp; ( 0.5 )&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 16:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796621#M255646</guid>
      <dc:creator>raja777pharma</dc:creator>
      <dc:date>2022-02-16T16:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove leading and traling space inside brackets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796624#M255649</link>
      <description>Show the code used to create that field instead and we can show you how to modify it.</description>
      <pubDate>Wed, 16 Feb 2022 16:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796624#M255649</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-16T16:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove leading and traling space inside brackets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796643#M255663</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/309000"&gt;@raja777pharma&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;Thank you for response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am wrongly post the data , i need to remove the space in side the bracket only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;infile datalines truncover;&lt;/P&gt;
&lt;P&gt;input_var $200;&lt;/P&gt;
&lt;P&gt;234&amp;nbsp; (&amp;nbsp; 23.5)&lt;/P&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;P&gt;12&amp;nbsp; &amp;nbsp;(&amp;nbsp; &amp;nbsp;34)&lt;/P&gt;
&lt;P&gt;30 ( 12.5)&lt;/P&gt;
&lt;P&gt;34&amp;nbsp; ( 0.5 )&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That data step still does not run. Incorrect statement: input _var&amp;nbsp; NOT input_var&lt;/P&gt;
&lt;P&gt;The Informat should end a dot: $200.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 17:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796643#M255663</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-16T17:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove leading and traling space inside brackets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796651#M255668</link>
      <description>&lt;P&gt;If the strings only have the one parenthetical value then I would just rebuild it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;"234  ( 23.5)"
"234  (23.5)"

"  0"
"  0"

" 12  (   34)"
" 12  (34)"

" 30  ( 12.5)"
" 30  (12.5)"

" 34  ( 0.5 )"
" 34  (0.5)"
&lt;/PRE&gt;
&lt;P&gt;PS: Your British is showing.&amp;nbsp; The characters used to include parentheticals are called parentheses.&amp;nbsp; Brackets look like this: [ ].&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 17:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796651#M255668</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-16T17:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove leading and traling space inside brackets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796856#M255746</link>
      <description>&lt;PRE&gt;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;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Feb 2022 12:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-leading-and-traling-space-inside-brackets/m-p/796856#M255746</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-02-17T12:43:14Z</dc:date>
    </item>
  </channel>
</rss>

