<?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 compress data value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142663#M296824</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Compress() will remove from the source string ALL characters listed in the compress function. &lt;/P&gt;&lt;P&gt;If this is not just a study question then you will have to be a bit more specific and provide some sample data with expected results for us to come up with an appropriate solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below code will replace the string "papaya" with a blank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; have="mango,orange,papaya";&lt;/P&gt;&lt;P&gt;&amp;nbsp; want = tranwrd(have,"papaya","");&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Dec 2014 08:08:18 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2014-12-09T08:08:18Z</dc:date>
    <item>
      <title>How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142659#M296820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to compress one of the value in the character string.&lt;/P&gt;&lt;P&gt;e..g, if value of string is "mango,orange,papaya" and I want to create a new variable with value "orange,papaya". I used below code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_var = compress(string,"mango");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and the result was new_var = ,re,ppy&lt;/P&gt;&lt;P&gt;Please suggest how can I do that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 07:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142659#M296820</guid>
      <dc:creator>abhee</dc:creator>
      <dc:date>2014-12-09T07:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142660#M296821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use findw and substr functions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 08:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142660#M296821</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-12-09T08:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142661#M296822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you please suggest sample syntax?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Abhee&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 08:06:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142661#M296822</guid>
      <dc:creator>abhee</dc:creator>
      <dc:date>2014-12-09T08:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142662#M296823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Support.sas.com &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 08:07:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142662#M296823</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-12-09T08:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142663#M296824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Compress() will remove from the source string ALL characters listed in the compress function. &lt;/P&gt;&lt;P&gt;If this is not just a study question then you will have to be a bit more specific and provide some sample data with expected results for us to come up with an appropriate solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below code will replace the string "papaya" with a blank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; have="mango,orange,papaya";&lt;/P&gt;&lt;P&gt;&amp;nbsp; want = tranwrd(have,"papaya","");&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 08:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142663#M296824</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-12-09T08:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142664#M296825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your prompt response. However I want to remove mango. I used below code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; have="mango,orange,papaya";&lt;/P&gt;&lt;P&gt;&amp;nbsp; want = tranwrd(have,"mango","");&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and the result was: want = ,,orange,papaya&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 08:16:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142664#M296825</guid>
      <dc:creator>abhee</dc:creator>
      <dc:date>2014-12-09T08:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142665#M296826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So it worked then.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 08:33:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142665#M296826</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-12-09T08:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142666#M296827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, it did not. I am getting comma also as I have mentioned earlier.&lt;/P&gt;&lt;P&gt;e.g.,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,,orange,papaya&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want: orange,papaya&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since I am working on confidential data, I am sorry I will not be able to share the sample data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 08:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142666#M296827</guid>
      <dc:creator>abhee</dc:creator>
      <dc:date>2014-12-09T08:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142667#M296828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try a do while loop over the data split by commas and then append each one where not your value to a new variable:&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; val="mango,orange,papaya";&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want (drop=i);&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; length processed $2000.;&lt;BR /&gt;&amp;nbsp; i=1;&lt;BR /&gt;&amp;nbsp; do while (scan(val,i,",") ne "");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if scan(val,i,",") ne "mango" then processed=catx(',',processed,scan(val,i,","));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=i+1;&lt;BR /&gt;&amp;nbsp; end;&amp;nbsp; &lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 09:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142667#M296828</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-12-09T09:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142668#M296829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just add a comma (,) to the end of mango.&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; have="mango,orange,papaya";&lt;/P&gt;&lt;P&gt;&amp;nbsp; want = tranwrd(have,"mango,","");&lt;/P&gt;&lt;P&gt;&amp;nbsp; putlog want=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if you want to handle situations, where mango can be at the beginning, end, and in the middle of the string... Maybe you need to use tranwrd 2 times. Once with "mango," then with ",mango".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 09:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142668#M296829</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2014-12-09T09:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142669#M296830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks RW9. It worked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 09:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142669#M296830</guid>
      <dc:creator>abhee</dc:creator>
      <dc:date>2014-12-09T09:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142670#M296831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The only thing I would add there Gergely is that you might end up with lots of tranwrds() nestled if you have more than one thing to remove, also you could run into problems trying to remove orange from "blood orange" for instance.&amp;nbsp; You could of course expand it with arrays and loops:&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; val="mango,orange,papaya,fruit,veg,apple,kiwi";&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want (drop=i j x removes1-removes4);&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; array removes{4} $20. ("mango","fruit","veg","orange");&lt;BR /&gt;&amp;nbsp; length processed $2000.;&lt;BR /&gt;&amp;nbsp; i=1;&lt;BR /&gt;&amp;nbsp; x=0;&lt;BR /&gt;&amp;nbsp; do while (scan(val,i,",") ne "");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j=1 to 4;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if scan(val,i,",")=removes{j} then x=1; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if x=0 then processed=catx(',',processed,scan(val,i,","));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=i+1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x=0;&lt;BR /&gt;&amp;nbsp; end;&amp;nbsp; &lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 09:55:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142670#M296831</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-12-09T09:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142671#M296832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would use regexp, if I have to remove more then one thing &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; val="papaya,mango,mango,orange,papaya,fruit,veg,apple,kiwi,orange,orange,papaya,papaya";&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want (keep=processed);&lt;/P&gt;&lt;P&gt;&amp;nbsp; array removes{4} $20. ("mango","fruit","veg","orange");&lt;/P&gt;&lt;P&gt;&amp;nbsp; length processed $2000;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length tmp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $200 ;&lt;/P&gt;&lt;P&gt;/*constructing the regexp*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to dim(removes);&lt;/P&gt;&lt;P&gt;&amp;nbsp; tmp=catx('|',tmp,'(,?'||strip(removes&lt;I&gt;)||')');&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;putlog tmp=;&lt;/P&gt;&lt;P&gt;&amp;nbsp; regexp=cats('s/',tmp,'//');&lt;/P&gt;&lt;P&gt;putlog regexp=;&lt;/P&gt;&lt;P&gt;&amp;nbsp; regexpid=prxparse(regexp);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; processed=prxchange(regexpid,-1,val);&lt;/P&gt;&lt;P&gt;&amp;nbsp; processed=prxchange('s/(^,)//',-1,processed);/*removing ',' from beginning*/&lt;/P&gt;&lt;P&gt;putlog processed=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 10:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142671#M296832</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2014-12-09T10:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to compress data value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142672#M296833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; val="mango,orange,papaya";&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data new;&lt;BR /&gt;set have;&lt;BR /&gt;val1= cats("'",substr(val,(find(val, ',')+1)),"'");&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Dec 2014 14:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compress-data-value/m-p/142672#M296833</guid>
      <dc:creator>Vix</dc:creator>
      <dc:date>2014-12-09T14:31:52Z</dc:date>
    </item>
  </channel>
</rss>

