<?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: Difference between strip, compress and trim in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323295#M271179</link>
    <description>&lt;P&gt;Run next code and learn the result of each function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    length text $15;
    format text $char15.;
    text = '  ab   cde  f   ';
    trim = '*'||trim(text)||'*';
    compress = '*'||compress(text)||'*';
    strip = '*'||strip(text)||'*';
    put trim= ;
    put compress= ;
    put strip=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;trim=*  ab   cde  f*
compress=*abcdef*
strip=*ab   cde  f*&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;See also the doc:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0xk6tl87f4b4qn1sp1ywen1ntan.htm&amp;amp;locale=en" target="_self"&gt;STRIP function&lt;/A&gt;&amp;nbsp;- removes all &lt;EM&gt;leading&lt;/EM&gt; and &lt;EM&gt;trailing&lt;/EM&gt; blanks&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n1io938ofitwnzn18e1hzel3u9ut.htm&amp;amp;locale=en" target="_self"&gt;TRIM function&lt;/A&gt;&amp;nbsp;- removes all &lt;EM&gt;trailing&lt;/EM&gt; blanks&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0fcshr0ir3h73n1b845c4aq58hz.htm&amp;amp;locale=en" target="_self"&gt;COMPRESS function&lt;/A&gt;&amp;nbsp;- removes &lt;STRONG&gt;all&lt;/STRONG&gt; blanks (by default - specify options to remove other chars)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Editor's note: modified this reply to include helpful info from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;and others.&lt;/EM&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Jun 2017 12:34:41 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-06-27T12:34:41Z</dc:date>
    <item>
      <title>What is the difference between strip, compress and trim?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323286#M271175</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you tell me which function i cannot use for removing leading and trailing spaces from a character text?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Pooja.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 20:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323286#M271175</guid>
      <dc:creator>pooja215</dc:creator>
      <dc:date>2021-06-04T20:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between strip, compress and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323287#M271176</link>
      <description>&lt;P&gt;The documentation is quite clear IMO. What is your doubt?&lt;/P&gt;
&lt;P&gt;This can be quite easily tested by using hard coded string in a data step, with comparisons/putting using $HEX. format.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 08:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323287#M271176</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-01-09T08:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between strip, compress and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323290#M271177</link>
      <description>Thanks for such an early response!&lt;BR /&gt;Which of the following cannot be used to "just" remove the leading and trailing spaces from character data?&lt;BR /&gt;&lt;BR /&gt;* Strip&lt;BR /&gt;&lt;BR /&gt;* Compress&lt;BR /&gt;&lt;BR /&gt;* Trim&lt;BR /&gt;Regards,&lt;BR /&gt;Pooja.&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Jan 2017 08:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323290#M271177</guid>
      <dc:creator>pooja215</dc:creator>
      <dc:date>2017-01-09T08:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between strip, compress and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323294#M271178</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   string = '    AB C D  ';

   strip_var    = strip(string);
   compress_var = compress(string);
   trim_var     = trim(string);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Jan 2017 09:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323294#M271178</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-01-09T09:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between strip, compress and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323295#M271179</link>
      <description>&lt;P&gt;Run next code and learn the result of each function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    length text $15;
    format text $char15.;
    text = '  ab   cde  f   ';
    trim = '*'||trim(text)||'*';
    compress = '*'||compress(text)||'*';
    strip = '*'||strip(text)||'*';
    put trim= ;
    put compress= ;
    put strip=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;trim=*  ab   cde  f*
compress=*abcdef*
strip=*ab   cde  f*&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;See also the doc:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0xk6tl87f4b4qn1sp1ywen1ntan.htm&amp;amp;locale=en" target="_self"&gt;STRIP function&lt;/A&gt;&amp;nbsp;- removes all &lt;EM&gt;leading&lt;/EM&gt; and &lt;EM&gt;trailing&lt;/EM&gt; blanks&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n1io938ofitwnzn18e1hzel3u9ut.htm&amp;amp;locale=en" target="_self"&gt;TRIM function&lt;/A&gt;&amp;nbsp;- removes all &lt;EM&gt;trailing&lt;/EM&gt; blanks&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0fcshr0ir3h73n1b845c4aq58hz.htm&amp;amp;locale=en" target="_self"&gt;COMPRESS function&lt;/A&gt;&amp;nbsp;- removes &lt;STRONG&gt;all&lt;/STRONG&gt; blanks (by default - specify options to remove other chars)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Editor's note: modified this reply to include helpful info from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;and others.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 12:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323295#M271179</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-27T12:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between strip, compress and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323300#M271180</link>
      <description>Thanks it really helped!!&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Jan 2017 09:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323300#M271180</guid>
      <dc:creator>pooja215</dc:creator>
      <dc:date>2017-01-09T09:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between strip, compress and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323305#M271181</link>
      <description>&lt;P&gt;And what does the manual say? &amp;nbsp;This is not a "question" as such, but asking someone to repeat what is clearly written in the manual. &amp;nbsp;I will paste tehm below for you:&lt;/P&gt;
&lt;P&gt;Strip:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002295689.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002295689.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Trim:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212226.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212226.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compress:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212246.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212246.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each page actually gives you examples of the use of each of them. &amp;nbsp;And links to other string compress/stripping functions which may be of use.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 09:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323305#M271181</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-09T09:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between strip, compress and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323320#M271182</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122397"&gt;@pooja215&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I guess this was in interview question. So now with all the information you've got, what would be your answer and why?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 10:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323320#M271182</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-09T10:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between strip, compress and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323322#M271183</link>
      <description>It wasn't an interview question. I got the information about trim, strip and compress in more detail.&lt;BR /&gt;The answer to my question was trim, as it did not remove the leading space from my text.&lt;BR /&gt;Regards,&lt;BR /&gt;Pooja.&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Jan 2017 10:43:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323322#M271183</guid>
      <dc:creator>pooja215</dc:creator>
      <dc:date>2017-01-09T10:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between strip, compress and trim</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323323#M271184</link>
      <description>&lt;P&gt;If you're using the question as you've formulated it the 2nd time&amp;nbsp;&lt;SPAN&gt;"&lt;EM&gt;Which of the following cannot be used to "just" remove the leading and trailing spaces from character data?&lt;/EM&gt;" then also compress() couldn't get used as it removes ALL blanks and not only the leading and trailing ones.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The two ways that's normally done:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;strip(&amp;lt;string&amp;gt;)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;trim(left(&amp;lt;string&amp;gt;))&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 10:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-difference-between-strip-compress-and-trim/m-p/323323#M271184</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-09T10:53:29Z</dc:date>
    </item>
  </channel>
</rss>

