<?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: Compress function treats slash as “or”? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918882#M361943</link>
    <description>&lt;P&gt;you can use prxchange again.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_string = prxchange('s/1\/2//', -1, text2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 04 Mar 2024 19:46:47 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2024-03-04T19:46:47Z</dc:date>
    <item>
      <title>Compress function treats slash as “or”?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918880#M361941</link>
      <description>Hi there, I would like to use compress function to take away any substring of “1/2”, but I found that it also removes any “1” or “2” from the string. E.g I have “20 1/2 Apple” and I want it to be “20 Apple”, but when I tried to use the compress function it gives me “0 Apple”.. is there anyway to use compress function to achieve this?&lt;BR /&gt;&lt;BR /&gt;This is my data:&lt;BR /&gt;Data have; input var 100$.;&lt;BR /&gt;Cards;&lt;BR /&gt;20 1/2 Apple&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;The code I tried is the following &lt;BR /&gt;var=compress(var, “1/2”) but it does not work.&lt;BR /&gt;&lt;BR /&gt;This is what I want:&lt;BR /&gt;Data want; input var 100$.;&lt;BR /&gt;Cards;&lt;BR /&gt;20 Apple&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Mar 2024 19:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918880#M361941</guid>
      <dc:creator>Feyng819</dc:creator>
      <dc:date>2024-03-04T19:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function treats slash as “or”?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918882#M361943</link>
      <description>&lt;P&gt;you can use prxchange again.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_string = prxchange('s/1\/2//', -1, text2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Mar 2024 19:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918882#M361943</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2024-03-04T19:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function treats slash as “or”?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918889#M361946</link>
      <description>&lt;P&gt;Read the documentation a bit more carefully:&lt;/P&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;H1 id="n0fcshr0ir3h73n1b845c4aq58hz" class="xis-title"&gt;&lt;A name="~1" target="_blank"&gt;&lt;/A&gt;&lt;FONT style="background-color: #fcdec0;"&gt;COMPRESS&lt;/FONT&gt; Function&lt;/H1&gt;
&lt;P class="xis-shortDescription"&gt;Returns a character string with specified &lt;STRONG&gt;characters&lt;/STRONG&gt; removed from the original string (emphasis added for character not string of characters)&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;So Compress removes all the characters you provide.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;If you want to replace a specific sequence of characters you might try TRANSTR&lt;/P&gt;
&lt;PRE&gt;Data have; 
   infile datalines truncover;
   input var $100.;
   want = transtrn(var,'1/2','');
Cards;
20 1/2 Apple
;
Run;&lt;/PRE&gt;
&lt;P class="xis-shortDescription"&gt;Note changes to your data step to actually read the value of VAR.&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 04 Mar 2024 19:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918889#M361946</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-04T19:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function treats slash as “or”?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918890#M361947</link>
      <description>&lt;P&gt;COMPRESS() is NOT what you want.&amp;nbsp; That removes CHARACTERS.&lt;/P&gt;
&lt;P&gt;So all of these statements are the same:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var=compress(var, '1/2') ;
var=compress(var, '12/') ;
var=compress(var, '/12') ;
var=compress(var, '21/') ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You want TRANWRD() or TRANSTRN() instead.&amp;nbsp; You can use COMPBL() collapse multiple adjacent spaces into just one space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var=compbl(tranwrd(var,'1/2',' '));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 20:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918890#M361947</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-04T20:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Compress function treats slash as “or”?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918915#M361959</link>
      <description>Thanks for your help!</description>
      <pubDate>Tue, 05 Mar 2024 00:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compress-function-treats-slash-as-or/m-p/918915#M361959</guid>
      <dc:creator>Feyng819</dc:creator>
      <dc:date>2024-03-05T00:17:26Z</dc:date>
    </item>
  </channel>
</rss>

