<?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 brackets and quotes from observations in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732604#M228294</link>
    <description>&lt;P&gt;Using compress() function as suggested by &lt;A class="trigger-hovercard" style="color: #009999;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879" target="_blank" rel="noopener"&gt;Reeza&lt;/A&gt; may have unintended consequences. For example, if you have legitimate single quotes in a name, such as ['O'Connor'], compress will remove ' after O as well. A cleaner way would be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="sas" style="font-family: monospace;"&gt;NAME = transtrn&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;NAME,"[&lt;SPAN style="color: #a020f0;"&gt;'"&lt;/SPAN&gt;,&lt;SPAN style="color: #0000ff;"&gt;trimn&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #a020f0;"&gt;''&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;;&lt;BR /&gt;NAME = transtrn&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;NAME,"']&lt;SPAN style="color: #a020f0;"&gt;"&lt;/SPAN&gt;,&lt;SPAN style="color: #0000ff;"&gt;trimn&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #a020f0;"&gt;''&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;This will selectively remove substring&lt;/P&gt;
&lt;PRE&gt;['&lt;/PRE&gt;
&lt;P&gt;and substring&lt;/P&gt;
&lt;PRE&gt;']&lt;/PRE&gt;
&lt;P&gt;For more information on this technique, see &lt;A href="https://blogs.sas.com/content/sgf/2021/02/22/deleting-a-substring-from-a-sas-string/" target="_self"&gt;Deleting a substring from a SAS string&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Apr 2021 19:06:04 GMT</pubDate>
    <dc:creator>LeonidBatkhan</dc:creator>
    <dc:date>2021-04-09T19:06:04Z</dc:date>
    <item>
      <title>How to remove brackets and quotes from observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732563#M228281</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of artists that is formatted like so:&lt;/P&gt;&lt;P&gt;['Justin Bieber']&lt;/P&gt;&lt;P&gt;['Brockhampton']&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I want to make it so these variables no longer have quotes or brackets and instead look like:&lt;/P&gt;&lt;P&gt;Justin Bieber&lt;/P&gt;&lt;P&gt;Brockhampton&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I do this?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 17:20:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732563#M228281</guid>
      <dc:creator>cfun</dc:creator>
      <dc:date>2021-04-09T17:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove brackets and quotes from observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732564#M228282</link>
      <description>&lt;P&gt;Additionally, this dataset contains many other variables, but I am fine with how they are formatted.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 17:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732564#M228282</guid>
      <dc:creator>cfun</dc:creator>
      <dc:date>2021-04-09T17:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove brackets and quotes from observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732565#M228283</link>
      <description>&lt;P&gt;COMPRESS()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x = compress(originalVar, "[]'");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the double quotes contain both brackets and single quote.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/377568"&gt;@cfun&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a list of artists that is formatted like so:&lt;/P&gt;
&lt;P&gt;['Justin Bieber']&lt;/P&gt;
&lt;P&gt;['Brockhampton']&lt;/P&gt;
&lt;P&gt;etc&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I want to make it so these variables no longer have quotes or brackets and instead look like:&lt;/P&gt;
&lt;P&gt;Justin Bieber&lt;/P&gt;
&lt;P&gt;Brockhampton&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would I do this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 17:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732565#M228283</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-09T17:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove brackets and quotes from observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732604#M228294</link>
      <description>&lt;P&gt;Using compress() function as suggested by &lt;A class="trigger-hovercard" style="color: #009999;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879" target="_blank" rel="noopener"&gt;Reeza&lt;/A&gt; may have unintended consequences. For example, if you have legitimate single quotes in a name, such as ['O'Connor'], compress will remove ' after O as well. A cleaner way would be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="sas" style="font-family: monospace;"&gt;NAME = transtrn&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;NAME,"[&lt;SPAN style="color: #a020f0;"&gt;'"&lt;/SPAN&gt;,&lt;SPAN style="color: #0000ff;"&gt;trimn&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #a020f0;"&gt;''&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;;&lt;BR /&gt;NAME = transtrn&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;NAME,"']&lt;SPAN style="color: #a020f0;"&gt;"&lt;/SPAN&gt;,&lt;SPAN style="color: #0000ff;"&gt;trimn&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #a020f0;"&gt;''&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;This will selectively remove substring&lt;/P&gt;
&lt;PRE&gt;['&lt;/PRE&gt;
&lt;P&gt;and substring&lt;/P&gt;
&lt;PRE&gt;']&lt;/PRE&gt;
&lt;P&gt;For more information on this technique, see &lt;A href="https://blogs.sas.com/content/sgf/2021/02/22/deleting-a-substring-from-a-sas-string/" target="_self"&gt;Deleting a substring from a SAS string&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 19:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732604#M228294</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2021-04-09T19:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove brackets and quotes from observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732612#M228298</link>
      <description>&lt;P&gt;Depends on whether those characters every appear in the actual data or not.&lt;/P&gt;
&lt;P&gt;If not then it is pretty simple.&amp;nbsp; So if your existing datasets is named HAVE and the existing variable is named VAR then you could use COMPRESS() to remove those three characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  var = compress(var,"[']");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could use SCAN() .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  var = scan(var,1,"[']");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If they appear in the data and the quotes are properly escaped then you might want to use SCAN() and DEQUOTE().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  var = dequote(scan(var,1,"[]",'q'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the embedded single quotes are "escaped" with \ instead of being doubled up then use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  var = dequote(scan(tranwrd(var,"\'","''"),1,"[]",'q'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If they are not protected in anyway then perhaps you just want to remove the first 2 and last 2 characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; var = substrn(var,3,length(var)-4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 19:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732612#M228298</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-09T19:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove brackets and quotes from observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732690#M228334</link>
      <description>&lt;P&gt;Couldl be simpler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input str $20.;
cards;
['Justin Bieber']
['Brockhampton']
['O'Connor']
;

data want;
 set have;
 want=prxchange("s/^\['|'\]$//",-1,strip(str));
 run;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Apr 2021 10:23:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732690#M228334</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-10T10:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove brackets and quotes from observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732818#M228357</link>
      <description>&lt;P&gt;As a variant to the RegEx&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;posted below RegEx will only remove ['....'] if it encloses the string and both parts exist.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input str $20.;
  cards;
['Justin Bieber']
['Brockhampton']
['O'Connor']
['O'['Con']nor']
['O'['Connor']
['O'Con']nor']
['O'Connor
O'Connor']
O'['Con']nor
;

data want;
  set have;
  length new_str $20;
  new_str=prxchange("s/^\['(.*)'\]/$1/oi",1,strip(str));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Apr 2021 06:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732818#M228357</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-11T06:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove brackets and quotes from observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732955#M228400</link>
      <description>&lt;P&gt;I am regex-fanboy, but in this case i don't see the need to use a regex.&lt;/P&gt;
&lt;P&gt;The first and last two chars should be removed, so why not just substr:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;clean = substr(str, 3, lengthn(str) - 4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 06:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/732955#M228400</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-04-12T06:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove brackets and quotes from observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/771071#M244631</link>
      <description>&lt;P&gt;How to remove brackets and quotes from observations in a dataset.&lt;/P&gt;&lt;P&gt;in my data having values 22.9()&amp;nbsp; and&amp;nbsp;1.9(mg/dl) like this but i want to remove&amp;nbsp; ()&amp;nbsp; without removing this brackets 1.9mg/dl&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 05:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/771071#M244631</guid>
      <dc:creator>Sri4_</dc:creator>
      <dc:date>2021-09-29T05:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove brackets and quotes from observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/771074#M244634</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/400787"&gt;@Sri4_&lt;/a&gt;&amp;nbsp; Please as this as a NEW question and don't just post into the middle of an "old" discussion that unfortunately never got closed.&lt;/P&gt;
&lt;P&gt;You can always reference another discussion in your NEW question.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 06:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-brackets-and-quotes-from-observations-in-a-dataset/m-p/771074#M244634</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-29T06:42:55Z</dc:date>
    </item>
  </channel>
</rss>

