<?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 %cmpres function works in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-cmpres-function-works/m-p/632871#M187685</link>
    <description>&lt;P&gt;The %CMPRES function removes multiple spaces, as well as leading and trailing spaces. However, it will preserve single spaces in between.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a= abcd efgh ijkl ;
%put %sysfunc(compress(&amp;amp;a));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Mar 2020 06:54:43 GMT</pubDate>
    <dc:creator>jvdl</dc:creator>
    <dc:date>2020-03-18T06:54:43Z</dc:date>
    <item>
      <title>How %cmpres function works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-cmpres-function-works/m-p/632858#M187678</link>
      <description>%let a=   abcd efgh ijkl ;&lt;BR /&gt;&lt;BR /&gt;%put %cmpres(&amp;amp;a) ;&lt;BR /&gt;&lt;BR /&gt;Above a macro variable not compressing.&lt;BR /&gt;The %cmpres how works &lt;BR /&gt;I need value like abcdefghijkl</description>
      <pubDate>Wed, 18 Mar 2020 05:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-cmpres-function-works/m-p/632858#M187678</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2020-03-18T05:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: How %cmpres function works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-cmpres-function-works/m-p/632862#M187683</link>
      <description>&lt;P&gt;Either run code preceding with &lt;STRONG&gt;options mprint symbolgen;&lt;/STRONG&gt; and post the log&lt;/P&gt;
&lt;P&gt;Or change code to&lt;STRONG&gt; %compress&lt;/STRONG&gt;(&amp;amp;a);&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 06:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-cmpres-function-works/m-p/632862#M187683</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-03-18T06:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: How %cmpres function works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-cmpres-function-works/m-p/632871#M187685</link>
      <description>&lt;P&gt;The %CMPRES function removes multiple spaces, as well as leading and trailing spaces. However, it will preserve single spaces in between.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a= abcd efgh ijkl ;
%put %sysfunc(compress(&amp;amp;a));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 06:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-cmpres-function-works/m-p/632871#M187685</guid>
      <dc:creator>jvdl</dc:creator>
      <dc:date>2020-03-18T06:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: How %cmpres function works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-cmpres-function-works/m-p/632933#M187706</link>
      <description>&lt;P&gt;Note that system macro is ancient.&amp;nbsp; You can use %SYSFUNC() now and avoid those macro loops.&amp;nbsp; To get similar results to %CMPRES() use %SYSFUNC(COMPBL()).&amp;nbsp; To remove all spaces use %SYSFUNC(COMPRESS()).&lt;/P&gt;
&lt;PRE&gt;152   %let a= abcd    efgh ijkl ;
153
154   %put a        |&amp;amp;a| ;
a        |abcd    efgh ijkl|
155   %put cmpress  |%cmpres(&amp;amp;a)| ;
cmpress  |abcd efgh ijkl|
156   %put compbl   |%sysfunc(compbl(&amp;amp;a))| ;
compbl   |abcd efgh ijkl|
157   %put compress |%sysfunc(compress(&amp;amp;a))| ;
compress |abcdefghijkl|
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to see how CMPRES works you can read the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro cmpres(text);
%*********************************************************************;
%*                                                                   *;
%*  MACRO: CMPRES                                                    *;
%*                                                                   *;
%*  USAGE: 1) %cmpres(argument)                                      *;
%*                                                                   *;
%*  DESCRIPTION:                                                     *;
%*    This macro returns the argument passed to it in an unquoted    *;
%*    form with multiple blanks compressed to single blanks and also *;
%*    with leading and trailing blanks removed.                      *;
%*                                                                   *;
%*    Eg. %let macvar=%cmpres(&amp;amp;argtext)                              *;
%*                                                                   *;
%*  NOTES:                                                           *;
%*    The %LEFT and %TRIM macros in the autocall library are used    *;
%*    in this macro.                                                 *;
%*                                                                   *;
%*********************************************************************;
%local i;
%let i=%index(&amp;amp;text,%str(  ));
%do %while(&amp;amp;i ne 0);
  %let text=%qsubstr(&amp;amp;text,1,&amp;amp;i)%qleft(%qsubstr(&amp;amp;text,&amp;amp;i+1));
  %let i=%index(&amp;amp;text,%str(  ));
%end;
%left(%qtrim(&amp;amp;text))
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course you will also need the code for the %LEFT() and %QTRIM() macros.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro left(text);                                                      
%*********************************************************************; 
%*                                                                   *; 
%*  MACRO: LEFT                                                      *; 
%*                                                                   *; 
%*  USAGE: 1) %left(argument)                                        *; 
%*                                                                   *; 
%*  DESCRIPTION:                                                     *; 
%*    This macro returns the argument passed to it without any       *; 
%*    leading blanks in an unquoted form. The syntax for its use     *; 
%*    is similar to that of native macro functions.                  *; 
%*                                                                   *; 
%*    Eg. %let macvar=%left(&amp;amp;argtext)                                *; 
%*                                                                   *; 
%*  NOTES:                                                           *; 
%*    The %VERIFY macro is used to determine the first non-blank     *; 
%*    character position.                                            *; 
%*                                                                   *; 
%*********************************************************************; 
%local i;                                                               
%if %length(&amp;amp;text)=0 %then %let text=%str( );                           
%let i=%verify(&amp;amp;text,%str( ));                                          
%if &amp;amp;i %then %substr(&amp;amp;text,&amp;amp;i);                                         
%mend;    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro qtrim(value);
%*********************************************************************;
%*                                                                   *;
%*  MACRO: QTRIM                                                     *;
%*                                                                   *;
%*  USAGE: 1) %qtrim(argument)                                       *;
%*                                                                   *;
%*  DESCRIPTION:                                                     *;
%*    This macro returns the argument passed to it without any       *;
%*    trailing blanks in a quoted form. The syntax for its use       *;
%*    is similar to that of native macro functions.                  *;
%*                                                                   *;
%*    Eg. %let macvar=%qtrim(&amp;amp;argtext)                               *;
%*                                                                   *;
%*  NOTES:                                                           *;
%*    None.                                                          *;
%*                                                                   *;
%*********************************************************************;
  %local i;
  %do i=%length(&amp;amp;value) %to 1 %by -1;
    %if %qsubstr(&amp;amp;value,&amp;amp;i,1) ne %str( ) %then %goto trimmed;
  %end;
  %trimmed: %if &amp;amp;i&amp;gt;0 %then %qsubstr(&amp;amp;value,1,&amp;amp;i);
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which to understand you will have to read the VERIFY macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro verify(text,target);
%*********************************************************************;
%*                                                                   *;
%*  MACRO: VERIFY                                                    *;
%*                                                                   *;
%*  USAGE: 1) %verify(argument,target)                               *;
%*                                                                   *;
%*  DESCRIPTION:                                                     *;
%*    This macro returns the position of the first character in the  *;
%*    argument that is not in the target value. If every character   *;
%*    that is in the argument is also in the target value then this  *;
%*    fuction returns a value of 0. The syntax for its use is        *;
%*    is similar to that of native macro functions.                  *;
%*                                                                   *;
%*    Eg. %let i=%verify(&amp;amp;argtext,&amp;amp;targtext)                         *;
%*                                                                   *;
%*  SUPPORT: sassmo                                                  *;
%*  NOTES:                                                           *;
%*    Both values to this function must have non-zero lengths or an  *;
%*    error message will be produced.                                *;
%*                                                                   *;
%*********************************************************************;
%local i;
%if %length(&amp;amp;text)=0 OR %length(&amp;amp;target)=0 %then %do;
  %put ERROR: ARGUMENT TO VERIFY FUNCTION MISSING.;

  %goto errout;
%end;
%do i=1 %to %length(&amp;amp;text);
  %if NOT %index(&amp;amp;target,%qsubstr(&amp;amp;text,&amp;amp;i,1)) %then %goto verfnd;
%end;
%verfnd: %if &amp;amp;i&amp;gt;%length(&amp;amp;text) %then 0;
           %else &amp;amp;i;
%errout:
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 12:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-cmpres-function-works/m-p/632933#M187706</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-18T12:21:12Z</dc:date>
    </item>
  </channel>
</rss>

