<?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: concatenate two macro variables in %let in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813851#M321252</link>
    <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;remarked, there are spaces in you macro variables, which get inserted into the result, for instance if they were created like this:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  a=783;
  b=9828888223;
  call symput ('a',put(a,12.0));
  call symput ('b',put(b,12.0));
run;
&lt;/PRE&gt;
&lt;P&gt;So, if you just join them in a %LET statement, the spaces will be conserved:&lt;/P&gt;
&lt;PRE&gt; 76         %put "&amp;amp;a.&amp;amp;b.";
 "         783  9828888223"&lt;/PRE&gt;
&lt;P&gt;And even if you do not use the quotes, there will still be spaces between the two numbers, because &amp;amp;B is right-aligned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest using the CATS function to get rid of the blanks, e.g.:&lt;/P&gt;
&lt;PRE&gt; 77         %put "%sysfunc(cats(&amp;amp;a,&amp;amp;b))";
 "7839828888223"&lt;/PRE&gt;
&lt;P&gt;The solution proposed by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;will also work, but explicitly calling the function as shown makes the code easier to read: Strip blanks from the inputs, and concatenate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If somebody else takes over the code as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;, it is not obvious what the two %LET statements are doing. So my suggestion is you use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a_b=%sysfunc(cats(&amp;amp;a,&amp;amp;b));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 May 2022 16:24:50 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2022-05-17T16:24:50Z</dc:date>
    <item>
      <title>concatenate two macro variables in %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813694#M321162</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;What is the way to concatenate two macro variables without space between them&amp;nbsp; in %let statement?&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;%let a_b=&amp;amp;a.&amp;amp;b.; &amp;nbsp;is&amp;nbsp;not&amp;nbsp;good&amp;nbsp;because&amp;nbsp;there&amp;nbsp;is&amp;nbsp;space&amp;nbsp;between&amp;nbsp;them?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Why&amp;nbsp;space&amp;nbsp;is&amp;nbsp;created&amp;nbsp;here?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a=783;
%let b=9828888223;
%let a_b=&amp;amp;a.&amp;amp;b.;  /**No good due to space**/&lt;BR /&gt;&lt;BR /&gt;/**Good way**/&lt;BR /&gt;Data _null_;&lt;BR /&gt;a_b=CATS(&amp;amp;a,&amp;amp;b.);&lt;BR /&gt;call symputx("a_b",a_b);&lt;BR /&gt;Run;&lt;BR /&gt;%put &amp;amp;a_b;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 May 2022 05:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813694#M321162</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-05-17T05:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two macro variables in %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813696#M321164</link>
      <description>&lt;P&gt;Good (code taken from the log):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;28         %let a = 783;
29         %let b = 9828888223;
30         %let a_b = &amp;amp;a.&amp;amp;b.;
31         
32         %put &amp;amp;a_b;
7839828888223&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: there is no space inserted.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 05:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813696#M321164</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-05-17T05:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two macro variables in %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813698#M321166</link>
      <description>If you are getting a space, it means that &amp;amp;a and &amp;amp;b were not created using the simple %let statements that you posted.  To remove the space (or spaces), run these statements:&lt;BR /&gt;&lt;BR /&gt;%let a = &amp;amp;a;&lt;BR /&gt;%let b = &amp;amp;b;&lt;BR /&gt;&lt;BR /&gt;Then add:&lt;BR /&gt;&lt;BR /&gt;%let a_b = &amp;amp;a.&amp;amp;b.;</description>
      <pubDate>Tue, 17 May 2022 06:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813698#M321166</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-05-17T06:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two macro variables in %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813720#M321176</link>
      <description>&lt;P&gt;There is no space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a=783;
%let b=9828888223;
%let a_b=&amp;amp;a.&amp;amp;b.;

data _null_;
a = "&amp;amp;a.";
b = "&amp;amp;b.";
a_b = "&amp;amp;a_b.";
l_a = length(a);
l_b = length(b);
l_ab = length(a_b);
put l_a= l_b= l_ab=;;
put a_b $hex26.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt; 69         %let a=783;
 70         %let b=9828888223;
 71         %let a_b=&amp;amp;a.&amp;amp;b.;
 72         
 73         data _null_;
 74         a = "&amp;amp;a.";
 75         b = "&amp;amp;b.";
 76         a_b = "&amp;amp;a_b.";
 77         l_a = length(a);
 78         l_b = length(b);
 79         l_ab = length(a_b);
 80         put l_a= l_b= l_ab=;;
 81         put a_b $hex26.;
 82         run;
 
 l_a=3 l_b=10 l_ab=13
 37383339383238383838323233
&lt;/PRE&gt;
&lt;P&gt;As you can see, the lengths add up correctly, and there is no space (hex 20) in the variable. In fact, you can see that there's only digits (hex codes 30 to 39).&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 08:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813720#M321176</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-17T08:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two macro variables in %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813851#M321252</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;remarked, there are spaces in you macro variables, which get inserted into the result, for instance if they were created like this:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  a=783;
  b=9828888223;
  call symput ('a',put(a,12.0));
  call symput ('b',put(b,12.0));
run;
&lt;/PRE&gt;
&lt;P&gt;So, if you just join them in a %LET statement, the spaces will be conserved:&lt;/P&gt;
&lt;PRE&gt; 76         %put "&amp;amp;a.&amp;amp;b.";
 "         783  9828888223"&lt;/PRE&gt;
&lt;P&gt;And even if you do not use the quotes, there will still be spaces between the two numbers, because &amp;amp;B is right-aligned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest using the CATS function to get rid of the blanks, e.g.:&lt;/P&gt;
&lt;PRE&gt; 77         %put "%sysfunc(cats(&amp;amp;a,&amp;amp;b))";
 "7839828888223"&lt;/PRE&gt;
&lt;P&gt;The solution proposed by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;will also work, but explicitly calling the function as shown makes the code easier to read: Strip blanks from the inputs, and concatenate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If somebody else takes over the code as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;, it is not obvious what the two %LET statements are doing. So my suggestion is you use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a_b=%sysfunc(cats(&amp;amp;a,&amp;amp;b));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 16:24:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813851#M321252</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-05-17T16:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two macro variables in %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813858#M321255</link>
      <description>&lt;P&gt;Except %SYSFUNC() does not work well with&amp;nbsp;functions. like CATS(), that can except either a numeric or a character value for the same argument position.&amp;nbsp; Poor %SYSFUNC() has to try to figure out what type of values it is giving CATS().&amp;nbsp; This can result it warnings and even incorrect results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To not add the spaces into the macro variables to begin with do not use the ancient CALL SYMPUT() function.&lt;/P&gt;
&lt;P&gt;Instead use CALL SYMPUTX() which will remove the leading/trailing spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When using PROC SQL to create macro variables include the TRIMMED keyword to remove the spaces.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 16:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813858#M321255</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-17T16:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two macro variables in %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813860#M321257</link>
      <description>&lt;P&gt;A possible detail of that "space" that is in your value is that it is not actually a space but another non-printable character.&lt;/P&gt;
&lt;P&gt;The macro processor will remove spaces by default but not so much other characters. Consider this code:&lt;/P&gt;
&lt;PRE&gt;%let a=783 ;
%let a2=783&amp;nbsp;;
%let b= 9828888223 ;
%let a_b=&amp;amp;a.&amp;amp;b.;
%let a2_b=&amp;amp;a2.&amp;amp;b;

%put a_b is:&amp;amp;a_b.;
%put a2_b is:&amp;amp;a2_b;&lt;/PRE&gt;
&lt;P&gt;Result is :&lt;/P&gt;
&lt;PRE&gt;138  %put a_b is:&amp;amp;a_b.;
a_b is:7839828888223
139  %put a2_b is:&amp;amp;a2_b;
a2_b is:783&amp;nbsp;9828888223
&lt;/PRE&gt;
&lt;P&gt;Why the difference? The A2 has a trailing null, entered in Windows with Alt-255 on the numeric keypad. So you may think it is a space but it may be a considerably different character and you need to address it. Since you did not include an actual example that duplicates your stated case then it is time to go back to your actual code that generates your two variables with any data used and show that.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 17:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813860#M321257</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-05-17T17:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two macro variables in %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813894#M321263</link>
      <description>&lt;P&gt;Good point, but I assumed that the inputs to %SYSFUNC(CATS()) would always be numeric, as in the example. In which case, "poor sysfunc" will not get confused, but just deliver the results as shown in my example.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 17:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813894#M321263</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-05-17T17:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two macro variables in %let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813896#M321264</link>
      <description>&lt;P&gt;BTW, %sysfunc does not get confused that easily:&lt;/P&gt;
&lt;PRE&gt; 69         %let a=%str(aaa  );
 70         %let b=1234;
 71         %put %sysfunc(cats(&amp;amp;a,&amp;amp;b));
 aaa1234&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 May 2022 17:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-macro-variables-in-let/m-p/813896#M321264</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-05-17T17:48:11Z</dc:date>
    </item>
  </channel>
</rss>

