<?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 concatenate two variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323201#M71594</link>
    <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to concatenate two variables(var1 and var2) . Can anyone suggest me how this can be done&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var1 &amp;nbsp;var2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Q1 &amp;nbsp; &amp;nbsp; Q3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Q1,Q3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The final output should&amp;nbsp;be like var3.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thaks in advance&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 08 Jan 2017 08:22:58 GMT</pubDate>
    <dc:creator>gowtham112</dc:creator>
    <dc:date>2017-01-08T08:22:58Z</dc:date>
    <item>
      <title>concatenate two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323201#M71594</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to concatenate two variables(var1 and var2) . Can anyone suggest me how this can be done&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var1 &amp;nbsp;var2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Q1 &amp;nbsp; &amp;nbsp; Q3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Q1,Q3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The final output should&amp;nbsp;be like var3.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thaks in advance&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2017 08:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323201#M71594</guid>
      <dc:creator>gowtham112</dc:creator>
      <dc:date>2017-01-08T08:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323204#M71596</link>
      <description>&lt;P&gt;Fortunately it's the simplest thing in the world. Well, not&amp;nbsp;&lt;EM&gt;the&lt;/EM&gt; simplest thing. But still fairly simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
var1 = 'Q1';
var2 = 'Q3';
length var3 $ 5;
var3 = catx(',', var1, var2);
put _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;catx&lt;/EM&gt; takes as its first parameter the separator you want, followed by the variables (and there can be many more) you want to concatenate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's magic!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;(Editor's note: see more details in &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-concatenate-values-in-SAS/ta-p/494125" target="_self"&gt;How to concatenate values in SAS.&lt;/A&gt;)&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Sep 2018 17:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323204#M71596</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2018-09-10T17:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323205#M71597</link>
      <description>&lt;P&gt;Like this? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input var1 $ var2 $;
   datalines;
   Q1 Q3
   ;

data want;
   set have;
   var3 = catx(',', var1, var2);
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Jan 2017 09:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323205#M71597</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-01-08T09:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323243#M71621</link>
      <description>I'd just like to add the the variables that are being concatenated are stripped (leading/trailing spaces taken off). In this case it doesn't make any difference, of course - just so that you know.</description>
      <pubDate>Mon, 09 Jan 2017 02:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323243#M71621</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-01-09T02:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323252#M71623</link>
      <description>&lt;P&gt;Same solution as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 04:40:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323252#M71623</guid>
      <dc:creator>mnjtrana</dc:creator>
      <dc:date>2017-01-09T04:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323253#M71624</link>
      <description>&lt;P&gt;I beat&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;by seconds, i think!&amp;nbsp;&lt;img id="smileytongue" class="emoticon emoticon-smileytongue" src="https://communities.sas.com/i/smilies/16x16_smiley-tongue.png" alt="Smiley Tongue" title="Smiley Tongue" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 04:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323253#M71624</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-01-09T04:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323408#M71675</link>
      <description>&lt;P&gt;As a minor clarification to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt;'s fine solution, the LENGTH of the new variable is important and needs to be set to the sum of the lengths of the longest values of Var1 and Var2 plus 1 for the comma. Otherwise you may experience truncation of your values. Note that CATX may tell that you need a longer variable with a message.&lt;/P&gt;
&lt;PRE&gt;data _null_;
   var1 = 'Q123';
   var2 = 'Q345';
   length var3 $ 8;
   var3 = catx(',', var1, var2);
   put _all_;
run;

&lt;/PRE&gt;
&lt;P&gt;Will generate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WARNING: In a call to the CATX function, the buffer allocated for the result was not long enough
         to contain the concatenation of all the arguments. The correct result would contain 9
         characters, but the actual result may either be truncated to 8 character(s) or be
         completely blank, depending on the calling environment. The following note indicates the
         left-most argument that caused truncation.
&lt;/PRE&gt;
&lt;P&gt;which tells the minimum length you should set for VAR3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 16:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/323408#M71675</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-09T16:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/474170#M121786</link>
      <description>Perfect! Thank you LaurieF</description>
      <pubDate>Thu, 28 Jun 2018 16:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-two-variables/m-p/474170#M121786</guid>
      <dc:creator>hmoghul</dc:creator>
      <dc:date>2018-06-28T16:56:54Z</dc:date>
    </item>
  </channel>
</rss>

