<?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 how to remove duplicate space within a marco variable value? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944939#M370229</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know whether there is a way to replace duplicate space to single space for the value of macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;%let _invar=A1 A2&amp;nbsp; &amp;nbsp;A3;&lt;/P&gt;
&lt;P&gt;Here you can see there are more than 1 space between A2 and A3. I would like to update _invar or build a new macro variable (_update) to 'A1 A2 A3'. Only 1 space between each word. What should I do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In data step, I could do&lt;/P&gt;
&lt;PRE&gt;COMPBL ("&amp;amp;_invar.")&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;however I am not sure how to do the similar process for a macro variable. Could anyone guide me on this? Thanks.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Sep 2024 17:37:36 GMT</pubDate>
    <dc:creator>stataq</dc:creator>
    <dc:date>2024-09-23T17:37:36Z</dc:date>
    <item>
      <title>how to remove duplicate space within a marco variable value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944939#M370229</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know whether there is a way to replace duplicate space to single space for the value of macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;%let _invar=A1 A2&amp;nbsp; &amp;nbsp;A3;&lt;/P&gt;
&lt;P&gt;Here you can see there are more than 1 space between A2 and A3. I would like to update _invar or build a new macro variable (_update) to 'A1 A2 A3'. Only 1 space between each word. What should I do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In data step, I could do&lt;/P&gt;
&lt;PRE&gt;COMPBL ("&amp;amp;_invar.")&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;however I am not sure how to do the similar process for a macro variable. Could anyone guide me on this? Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 17:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944939#M370229</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-09-23T17:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove duplicate space within a marco variable value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944941#M370231</link>
      <description>&lt;P&gt;You can use %SYSFUNC() in macro code to call many SAS functions.&amp;nbsp; It works for COMPBL().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varlist=A    b  C;
%let varlist=%sysfunc(compbl(&amp;amp;varlist));
%put &amp;amp;=varlist;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Sep 2024 17:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944941#M370231</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-23T17:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove duplicate space within a marco variable value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944942#M370232</link>
      <description>&lt;P&gt;Consider using the&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/default/mcrolref/n0tvdbcgr9xc6dn14wmx9hpd6h51.htm" target="_self"&gt;%QCMPRES&lt;/A&gt; autocall macro provided with base SAS.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 17:41:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944942#M370232</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-09-23T17:41:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove duplicate space within a marco variable value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944979#M370242</link>
      <description>&lt;P&gt;Jedi,&lt;BR /&gt;Also %CMPRES autocall macro as well.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;1    %let varlist=A    b  C;
2    %let varlist=%cmpres(&amp;amp;varlist);
3    %put &amp;amp;=varlist;
VARLIST=A b C
4    %let varlist=A    b  C;
5    %let varlist=%qcmpres(&amp;amp;varlist);
6    %put &amp;amp;=varlist;
VARLIST=A b C
&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Sep 2024 01:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944979#M370242</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-09-24T01:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove duplicate space within a marco variable value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944986#M370245</link>
      <description>&lt;P&gt;Note that those are left overs from before the %SYSFUNC() macro function was created.&amp;nbsp; Not really any reason to use them now.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2024 02:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/944986#M370245</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-24T02:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove duplicate space within a marco variable value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/945197#M370318</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;- true, but IMHO, %QCMPRES is generally a "safer" option. Because the results are returned pre-quoted, the macro processor will never process the returned text as additional macro code or references. In my decades of macro programming, about 80% of my troubleshooting efforts (correlating to about 80% of my hair loss&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;) have boiled down to under-quoted text being inadvertently resolved and reprocessed by the macro processor. So I always quote results unless I intend to use send the result back to the macro processor for further processing. For example, if I went with the answer provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; I would have used %QSYSFUNC instead fo %SYSFUNC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess it all depends on how much hair you are willing to sacrifice&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 13:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/945197#M370318</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-09-25T13:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove duplicate space within a marco variable value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/945207#M370324</link>
      <description>&lt;P&gt;Macro quoting does not only "solve" problems.&amp;nbsp; It can also "cause" problems.&lt;/P&gt;
&lt;P&gt;So use the version %QSYSFUNC() if you want macro quoting added and %SYSFUNC() if you want macro quoting removed.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 14:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/945207#M370324</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-25T14:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove duplicate space within a marco variable value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/945256#M370349</link>
      <description>&lt;P&gt;In my experience, less than 1% of macro program failures due to quoting issues have been caused by overquoting - so my default behavior is to quote. In situations where I am &lt;EM&gt;absolutely positive&lt;/EM&gt; that processing the text will not produce characters that can be misinterpreted as code, will sometimes use the "non-Q" version of these functions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This example was obviously simplified by the OP to clarify the question. Not being sure of the ultimate application (and deeply desiring to preserve the OP's remaining hair&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;) I chose to recommend %QCMPRES and I have not changed my mind. His (and your) mileage may vary, of course, and we're all SAS coders&amp;nbsp; - free to make our own coding decisions. Having options provided is always nice.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 18:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/945256#M370349</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-09-25T18:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove duplicate space within a marco variable value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/957336#M373724</link>
      <description>&lt;P&gt;Hello, I have started to learn macro for a little while and I think this post is interesting and helpful. I tried both %sysfunc(compbl()) and %qcmpres() functions, they produce exactly the same results (see below) and %qcmpres saves a lot of typing. I have been used to use %sysfunc() when writing macro because I learnt it first and it is handy. I guess later on I will use functions such as %qcmpres(), %qscan(), and %qsysfunc() more.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled3.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104028i6AE3572B0A11C843/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Untitled3.png" alt="Untitled3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 19:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/957336#M373724</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-01-27T19:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove duplicate space within a marco variable value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/957339#M373726</link>
      <description>&lt;P&gt;One of those things is not like the others.&lt;/P&gt;
&lt;P&gt;%QSCAN() and %QSYSFUNC() are built in macro functions.&amp;nbsp; Part of the macro language.&lt;/P&gt;
&lt;P&gt;%QCMPRES() is a user written macro. (actually four user written macros since it calls %QLEFT() and %QTRIM() macros and they call the %VERIFY() macro.)&lt;/P&gt;
&lt;P&gt;It just happens to be supplied by SAS as part of their autocall library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can check out the source code yourself.&amp;nbsp; For example by using %INCLUDE with the /SOURCE2 option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include sasautos(qcmpres qleft qtrim verify) / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If you want to save typing a few characters write your own macro with a shorter name.&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro qb(string);
%qsysfunc(compbl(&amp;amp;string))
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then use that macro instead.&lt;/P&gt;
&lt;PRE&gt; 75         %put %qb(A   b  C);
 A b C&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This version seems very robust.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro qcompbl / parmbuff;
%if %length(&amp;amp;syspbuff)&amp;gt;2 %then %qsysfunc(compbl(%quote&amp;amp;syspbuff));
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Jan 2025 19:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-duplicate-space-within-a-marco-variable-value/m-p/957339#M373726</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-27T19:52:50Z</dc:date>
    </item>
  </channel>
</rss>

