<?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 to concatenate values in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/744873#M233415</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316144"&gt;@sagarwal1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I will consider using the CATX method provided by SAS. It automatically takes care of trailing space but assigns 200 bytes of space to the new variable. For that, users can use the LENGTH method to use a certain space.&lt;/P&gt;
&lt;P&gt;Syntax -- CATX(' delimiter ', first_var, second_var, ....and more).&lt;/P&gt;
&lt;P&gt;Another method --&amp;gt; This is a little bit long but gives the same result using TRIM and ' || '.&lt;/P&gt;
&lt;P&gt;Syntax -- TRIM(first_var) || ' delimiter ' || TRIM(second_var) || ' delimiter ' || ......and more.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not only can you use the LENGTH statement (prior to the CATX call) to override the default length of 200, you can also do something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if _n_=1 then newvar=oldvar1 || oldvar2 || oldvar3;
  newvar=catx('!',oldvar1,oldvar2,oldvar3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;EM&gt;&lt;STRONG&gt;"if _n_=1 then newvar=..."&lt;/STRONG&gt;&lt;/EM&gt; statement obligates the SAS compiler to calculate a length for newvar, by summing the lengths of oldvar1, oldvar2, and oldvar3.&amp;nbsp; This could be useful if you are going to apply CATX to a changing list of variables (possibly specified in a macro).&amp;nbsp; No need for you to determine a safe length by checking changing variable lists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition.&amp;nbsp; To be precise about this technique, you have to generate a length that also accounts for the delimiter used by catx.&amp;nbsp; Something like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if 0 then newvar=oldvar1 || '!' || oldvar2 || '!' || || '!' oldvar3;
  newvar=catx('!',oldvar1,oldvar2,oldvar3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW, using "if 0" means the statement is never actually executed, but the SAS compiler still has to do its job of making provision for newvar.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Jun 2021 13:15:03 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-06-21T13:15:03Z</dc:date>
    <item>
      <title>How to: Concatenate values in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/580257#M164804</link>
      <description>&lt;P&gt;The most-viewed SAS Communities Library article is this one: &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;. The word "concatenate" isn't part of my everyday vernacular, but I bet it's in yours. Google's doing a fine job of helping folks find the article, but thought I'd create this post and pin it in a conspicuous place. You're welcome! Hit the orange button to learn about SAS software's most common&amp;nbsp;&lt;SPAN&gt;CAT* functions.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-concatenate-values-in-SAS/ta-p/494125" target="_blank" rel="noopener"&gt;&lt;SPAN class="cta-button-article"&gt;Concatenate Now&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2020 02:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/580257#M164804</guid>
      <dc:creator>BeverlyBrown</dc:creator>
      <dc:date>2020-12-21T02:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate values in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/584095#M166301</link>
      <description>&lt;P&gt;Thank for this&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34537"&gt;@BeverlyBrown&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;I guess another good topic to pin would be&amp;nbsp;"Converting a numeric variable into character".&lt;/P&gt;
&lt;P&gt;This matter comes back rather often as well, including &lt;A href="https://communities.sas.com/t5/SAS-Programming/Converting-a-numeric-variable-into-character/m-p/583926#M166265" target="_self"&gt;yesterday&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 22:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/584095#M166301</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-08-26T22:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate values in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/584229#M166344</link>
      <description>&lt;P&gt;Good point! Got a new video covering that. I'll pin it too.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 13:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/584229#M166344</guid>
      <dc:creator>BeverlyBrown</dc:creator>
      <dc:date>2019-08-27T13:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate values in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/600717#M173695</link>
      <description>&lt;P&gt;Great! Thanks for Sharing&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2019 14:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/600717#M173695</guid>
      <dc:creator>manikandanms</dc:creator>
      <dc:date>2019-10-31T14:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate values in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/655604#M196692</link>
      <description>&lt;P&gt;I will consider using the CATX method provided by SAS. It automatically takes care of trailing space but assigns 200 bytes of space to the new variable. For that, users can use the LENGTH method to use a certain space.&lt;/P&gt;&lt;P&gt;Syntax -- CATX(' delimiter ', first_var, second_var, ....and more).&lt;/P&gt;&lt;P&gt;Another method --&amp;gt; This is a little bit long but gives the same result using TRIM and ' || '.&lt;/P&gt;&lt;P&gt;Syntax -- TRIM(first_var) || ' delimiter ' || TRIM(second_var) || ' delimiter ' || ......and more.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 17:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/655604#M196692</guid>
      <dc:creator>sagarwal1</dc:creator>
      <dc:date>2020-06-09T17:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate values in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/744873#M233415</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316144"&gt;@sagarwal1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I will consider using the CATX method provided by SAS. It automatically takes care of trailing space but assigns 200 bytes of space to the new variable. For that, users can use the LENGTH method to use a certain space.&lt;/P&gt;
&lt;P&gt;Syntax -- CATX(' delimiter ', first_var, second_var, ....and more).&lt;/P&gt;
&lt;P&gt;Another method --&amp;gt; This is a little bit long but gives the same result using TRIM and ' || '.&lt;/P&gt;
&lt;P&gt;Syntax -- TRIM(first_var) || ' delimiter ' || TRIM(second_var) || ' delimiter ' || ......and more.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not only can you use the LENGTH statement (prior to the CATX call) to override the default length of 200, you can also do something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if _n_=1 then newvar=oldvar1 || oldvar2 || oldvar3;
  newvar=catx('!',oldvar1,oldvar2,oldvar3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;EM&gt;&lt;STRONG&gt;"if _n_=1 then newvar=..."&lt;/STRONG&gt;&lt;/EM&gt; statement obligates the SAS compiler to calculate a length for newvar, by summing the lengths of oldvar1, oldvar2, and oldvar3.&amp;nbsp; This could be useful if you are going to apply CATX to a changing list of variables (possibly specified in a macro).&amp;nbsp; No need for you to determine a safe length by checking changing variable lists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition.&amp;nbsp; To be precise about this technique, you have to generate a length that also accounts for the delimiter used by catx.&amp;nbsp; Something like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if 0 then newvar=oldvar1 || '!' || oldvar2 || '!' || || '!' oldvar3;
  newvar=catx('!',oldvar1,oldvar2,oldvar3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW, using "if 0" means the statement is never actually executed, but the SAS compiler still has to do its job of making provision for newvar.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 13:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Concatenate-values-in-SAS/m-p/744873#M233415</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-06-21T13:15:03Z</dc:date>
    </item>
  </channel>
</rss>

