<?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 can I add a underscore at the end of each macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-add-a-underscore-at-the-end-of-each-macro-variable/m-p/872088#M344532</link>
    <description>&lt;P&gt;How can I add a underscore at the end of each macro variable?&lt;/P&gt;
&lt;P&gt;For example, I have: %LET mvar= var1 var2 var2.. I want mvar to contain var1_ var2_ var2_&lt;/P&gt;</description>
    <pubDate>Wed, 26 Apr 2023 03:03:20 GMT</pubDate>
    <dc:creator>bayzid</dc:creator>
    <dc:date>2023-04-26T03:03:20Z</dc:date>
    <item>
      <title>How can I add a underscore at the end of each macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-add-a-underscore-at-the-end-of-each-macro-variable/m-p/872088#M344532</link>
      <description>&lt;P&gt;How can I add a underscore at the end of each macro variable?&lt;/P&gt;
&lt;P&gt;For example, I have: %LET mvar= var1 var2 var2.. I want mvar to contain var1_ var2_ var2_&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 03:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-add-a-underscore-at-the-end-of-each-macro-variable/m-p/872088#M344532</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-04-26T03:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a underscore at the end of each macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-add-a-underscore-at-the-end-of-each-macro-variable/m-p/872095#M344534</link>
      <description>&lt;P&gt;That is adding underscores in the MIDDLE of the VALUE of the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know that the string only has one space between the words then you can use TRANWRD() function.&amp;nbsp; You will have to use the %SYSFUNC() macro function to use TRANWRD() function in macro code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mvar=%sysfunc(tranwrd(&amp;amp;mvar,%str( ),%str(_ )))_;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are worried it might have multiple spaces between the words then use COMPBL() first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mvar=%sysfunc(tranwrd(%sysfunc(compbl(&amp;amp;mvar)),%str( ),%str(_ )))_;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example&lt;/P&gt;
&lt;PRE&gt;818  %LET mvar= var1   var2   var2 ;
819
820  %let mvar=%sysfunc(tranwrd(%sysfunc(compbl(&amp;amp;mvar)),%str( ),%str(_ )))_;
821
822  %put &amp;amp;=mvar;
MVAR=var1_ var2_ var2_
&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2023 03:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-add-a-underscore-at-the-end-of-each-macro-variable/m-p/872095#M344534</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-26T03:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a underscore at the end of each macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-add-a-underscore-at-the-end-of-each-macro-variable/m-p/872218#M344585</link>
      <description>&lt;PRE&gt; %LET mvar= var1   var2   var2 ;

 %let mvar=%sysfunc(prxchange(s/(\w+)/$1_/,-1,&amp;amp;mvar));

 %put &amp;amp;=mvar;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2023 11:54:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-add-a-underscore-at-the-end-of-each-macro-variable/m-p/872218#M344585</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-04-26T11:54:25Z</dc:date>
    </item>
  </channel>
</rss>

