<?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 variables with out removing leading and trailing spaces in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/503994#M134805</link>
    <description>&lt;P&gt;Sorry,came across this while chasing another problem..&lt;/P&gt;&lt;P&gt;lengthc() returns length of the string including trailing blanks. However, for character fields in SAS datasets, lengthc() always returns the length of the field defined in the SAS dataset. This is because SAS stores the value by padding it with blanks to fill the defined length.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 13 Oct 2018 07:35:03 GMT</pubDate>
    <dc:creator>ksj</dc:creator>
    <dc:date>2018-10-13T07:35:03Z</dc:date>
    <item>
      <title>concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437445#M108915</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to concatenate the 3 variables in to one with out removing leading and trailing blanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is in the datastep.&lt;/P&gt;&lt;P&gt;concatenate = trim(concatenate)||trim(value); --&amp;gt; this will remove the trailing blanks. I don't need to remove any blanks. I need what is exactly in the rows(including trailing and leading blanks).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could any one please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;INPUT:&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="measures.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18599i5AB07599724639B2/image-size/large?v=v2&amp;amp;px=999" role="button" title="measures.PNG" alt="measures.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;MEASURES3=cnt_pol_COMBINE sum_pol_COMBINE cnt_pol_QA sum_pol_QA cnt_pol_FO sum_pol_FO cnt_pol_FACNP sum_pol_FACNP cnt_pol_PQS sum_pol_PQS cnt_pol_SURPLUS1 sum_pol_SURPLUS1 cnt_pol_SURPLUS2 sum_pol_SURPLUS2 cnt_&lt;/P&gt;&lt;P&gt;MEASURES3=pol_FACPROP sum_pol_FACPROP cnt_pol_OTHER sum_pol_OTHER cnt_ins_COMBINE sum_ins_COMBINE cnt_ins_QA sum_ins_QA cnt_ins_FO sum_ins_FO cnt_ins_FACNP sum_ins_FACNP cnt_ins_PQS sum_ins_PQS cnt_ins_SURPLUS1&lt;/P&gt;&lt;P&gt;MEASURES3= sum_ins_SURPLUS1 cnt_ins_SURPLUS2 sum_ins_SURPLUS2 cnt_ins_FACPROP sum_ins_FACPROP cnt_ins_OTHER sum_ins_OTHER&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;OUTPUT:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="measures_ou.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18600i2FE63A73C0007762/image-size/large?v=v2&amp;amp;px=999" role="button" title="measures_ou.PNG" alt="measures_ou.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MEASURES3 = cnt_pol_COMBINE sum_pol_COMBINE cnt_pol_QA sum_pol_QA cnt_pol_FO sum_pol_FO cnt_pol_FACNP sum_pol_FACNP cnt_pol_PQS sum_pol_PQS cnt_pol_SURPLUS1 sum_pol_SURPLUS1 cnt_pol_SURPLUS2 sum_pol_SURPLUS2 cnt_pol_FACPROP sum_pol_FACPROP cnt_pol_OTHER sum_pol_OTHER cnt_ins_COMBINE sum_ins_COMBINE cnt_ins_QA sum_ins_QA cnt_ins_FO sum_ins_FO cnt_ins_FACNP sum_ins_FACNP cnt_ins_PQS sum_ins_PQS cnt_ins_SURPLUS1 sum_ins_SURPLUS1 cnt_ins_SURPLUS2 sum_ins_SURPLUS2 cnt_ins_FACPROP sum_ins_FACPROP cnt_ins_OTHER sum_ins_OTHER;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 08:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437445#M108915</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-02-15T08:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437449#M108917</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to keep the blanks, don't use the trim function.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 08:44:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437449#M108917</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-02-15T08:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437458#M108920</link>
      <description>&lt;P&gt;concatenate=cat(concatenate,value);&lt;/P&gt;
&lt;P&gt;See the help documentation on all of the concat functions available:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002257060.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002257060.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 09:02:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437458#M108920</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-15T09:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437463#M108923</link>
      <description>&lt;P&gt;when using cat(concatenate,value) I am getting null value.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 09:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437463#M108923</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-02-15T09:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437472#M108928</link>
      <description>&lt;P&gt;You asked to keep trailing spaces.&amp;nbsp; That is what it is doing.&amp;nbsp; A text string is is text padded out to the length of the variable with spaces.&amp;nbsp; Therefore if you have concatenate variable set as 200, that is 200 spaces.&amp;nbsp; if value is length 200, and has 4 characters then when you concatenate the variable concatenate, only the first 200 characters are stored, which as that is the first variable is the whole data.&lt;/P&gt;
&lt;P&gt;Why not start by postings some test data in the form of a datastep (so we can run it), and what you want out.&amp;nbsp; Is likeli you want a list of variables delimited by a space, so maybe:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  by id;
  want=ifc(first.id,strip(value),catx(' ',want,value));
  if last.id;
run;
&lt;/PRE&gt;
&lt;P&gt;This takes the text from value in the first occurence, and concatenates trimmed want, a space, and trimmed value from there after.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 09:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437472#M108928</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-15T09:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437479#M108932</link>
      <description>&lt;P&gt;Many Thanks for your explanation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to concatenate the 3 rows exactly. not include any delimeters in between.&lt;/P&gt;&lt;P&gt;you can see in the third macro(below) :&lt;/P&gt;&lt;P&gt;MEASURES3= sum_ins_SURPLUS1 cnt_ins_SURPLUS2 sum_ins_SURPLUS2 cnt_ins_FACPROP sum_ins_FACPROP cnt_ins_OTHER sum_ins_OTHER&lt;/P&gt;&lt;P&gt;There is a leading space. So, during concatenation this should also be there.&lt;/P&gt;&lt;P&gt;Also, maybe in some case there maybe trailing blanks as well, that case also.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 09:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437479#M108932</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-02-15T09:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437482#M108933</link>
      <description>&lt;P&gt;Post test data, your example does not show the required things.&amp;nbsp; All text fields have trailing blanks up to the length of the variable - look at this example:&lt;/P&gt;
&lt;PRE&gt;data want;
  length first $10 second $10 final $21;
  first="abc";
  second="def";
  final=cat(first,'-',second);
run;&lt;/PRE&gt;
&lt;P&gt;What you will see is that I specify the text of first as being "abc", but it is stored as "abc&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ", because its length is 10.&amp;nbsp; Normally you would need to trim off the additional spaces, but I can't tell from that data wether there should be one space after that text, or 2, or 7?&amp;nbsp; This also shows why presenting test data&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;in the form of a datastep so that we can run it&lt;/STRONG&gt;&lt;/U&gt; is very important to understanding what you have.&amp;nbsp; Follow this post if your having difficulties:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 10:07:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437482#M108933</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-15T10:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437491#M108938</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; b $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;apple rose&lt;/P&gt;&lt;P&gt;apple lotus&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=a;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; macros(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=b);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; concatenate $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;100&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;until&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (last.a);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;concatenate = cat(concatenate,b);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above is a sample program where cat function is not working for me.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 10:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437491#M108938</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-02-15T10:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437492#M108939</link>
      <description>&lt;P&gt;This will give you a list of all values in b concatenated by a space, all you need to do is add if last.a to get only this record:&lt;/P&gt;
&lt;PRE&gt;data a;
  length a b $10;
  input a $ b $;
datalines;
apple rose
apple lotus
;
run;

proc sort data=a;
  by a;
quit;

data macros (drop=b /*rename=(concatenate=b)*/);
  length concatenate $100;
  retain concatenate;
  set a;
  by a;
  concatenate=ifc(first.a,strip(b),catx(' ',concatenate,b));
run;&lt;/PRE&gt;
&lt;P&gt;Note how I set length on the input variables, and this is less that the 100, so both concatenated are length 20 which will fit in the 100 output variable.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 10:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437492#M108939</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-15T10:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437497#M108942</link>
      <description>&lt;P&gt;Yes. Thanks.&lt;/P&gt;&lt;P&gt;But I need a concatenated string without space. :(&lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://communities.sas.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 10:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437497#M108942</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-02-15T10:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437501#M108946</link>
      <description>&lt;PRE&gt;  concatenate=ifc(first.a,strip(b),catx(' ',concatenate,b));&lt;/PRE&gt;
&lt;P&gt;To:&lt;/P&gt;
&lt;PRE&gt;  concatenate=ifc(first.a,strip(b),cat(concatenate,b));&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;String functions explained:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002257060.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002257060.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 10:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437501#M108946</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-15T10:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437505#M108948</link>
      <description>&lt;P&gt;concatenate=ifc(first.a,strip(b),cat(concatenate,b))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is not working&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 11:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437505#M108948</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-02-15T11:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437512#M108953</link>
      <description>&lt;P&gt;Cats():&lt;/P&gt;
&lt;PRE&gt;data a;
  length a b $10;
  input a $ b $;
datalines;
apple rose
apple lotus
;
run;

proc sort data=a;
  by a;
quit;

data macros (drop=b /*rename=(concatenate=b)*/);
  length concatenate $100;
  retain concatenate;
  set a;
  by a;
  concatenate=ifc(first.a,strip(b),cats(concatenate,b));
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 11:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437512#M108953</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-15T11:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437526#M108959</link>
      <description>&lt;P&gt;Thanks. But cats will remove leading and trailing blanks.&lt;/P&gt;&lt;P&gt;In my case, leading and trailing blanks will come. So, I don't want to remove that, I need that as well&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 11:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437526#M108959</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-02-15T11:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437532#M108961</link>
      <description>&lt;P&gt;The following is working, tested. No Leading or trailing blanks removed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
MEASURES1='cnt_pol_COMBINE sum_pol_COMBINE cnt_pol_QA sum_pol_QA cnt_pol_FO sum_pol_FO cnt_pol_FACNP sum_pol_FACNP cnt_pol_PQS sum_pol_PQS cnt_pol_SURPLUS1 sum_pol_SURPLUS1 cnt_pol_SURPLUS2 sum_pol_SURPLUS2 cnt_';
MEASURES2='pol_FACPROP sum_pol_FACPROP cnt_pol_OTHER sum_pol_OTHER cnt_ins_COMBINE sum_ins_COMBINE cnt_ins_QA sum_ins_QA cnt_ins_FO sum_ins_FO cnt_ins_FACNP sum_ins_FACNP cnt_ins_PQS sum_ins_PQS cnt_ins_SURPLUS1';
MEASURES3=' sum_ins_SURPLUS1 cnt_ins_SURPLUS2 sum_ins_SURPLUS2 cnt_ins_FACPROP sum_ins_FACPROP cnt_ins_OTHER sum_ins_OTHER';
MEASURES4=MEASURES1||MEASURES2||MEASURES3;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please let us know if it worked for you.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 12:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437532#M108961</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-02-15T12:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437536#M108963</link>
      <description>&lt;P&gt;Yes, working..Thanks.&lt;/P&gt;&lt;P&gt;But what happens when it comes to a sas table? It will not work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here it is a quoted string. But in my case these values are in a sas table.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 12:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437536#M108963</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-02-15T12:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437544#M108966</link>
      <description>&lt;P&gt;In that case this will also work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is no space timing, it is old school concatenation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have done the same thing in 2 steps just to demonstrate it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
MEASURES1='cnt_pol_COMBINE sum_pol_COMBINE cnt_pol_QA sum_pol_QA cnt_pol_FO sum_pol_FO cnt_pol_FACNP sum_pol_FACNP cnt_pol_PQS sum_pol_PQS cnt_pol_SURPLUS1 sum_pol_SURPLUS1 cnt_pol_SURPLUS2 sum_pol_SURPLUS2 cnt_';
MEASURES2='pol_FACPROP sum_pol_FACPROP cnt_pol_OTHER sum_pol_OTHER cnt_ins_COMBINE sum_ins_COMBINE cnt_ins_QA sum_ins_QA cnt_ins_FO sum_ins_FO cnt_ins_FACNP sum_ins_FACNP cnt_ins_PQS sum_ins_PQS cnt_ins_SURPLUS1';
MEASURES3=' sum_ins_SURPLUS1 cnt_ins_SURPLUS2 sum_ins_SURPLUS2 cnt_ins_FACPROP sum_ins_FACPROP cnt_ins_OTHER sum_ins_OTHER';
run;

data want;
set have;
MEASURES4=MEASURES1||MEASURES2||MEASURES3;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For real time,&lt;/P&gt;&lt;P&gt;1. if you know the number of vars you going to concatenate then define the length of final string in advance,&lt;/P&gt;&lt;P&gt;2. Please keep in mind the maximum length of character variables in this case, which is around 32000.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 12:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437544#M108966</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-02-15T12:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437550#M108970</link>
      <description>&lt;P&gt;Assuming&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(1) Your incoming data set contains up to 5 observations, and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(2) You are only doing this for one variable (MEASURES3)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(3) The length of VALUE is $ 200:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have end=done;&lt;/P&gt;
&lt;P&gt;where name='MEASURES3';&lt;/P&gt;
&lt;P&gt;length measures3 $ 1000;&lt;/P&gt;
&lt;P&gt;retain measures3;&lt;/P&gt;
&lt;P&gt;substr(measures3, 1 + 200*(_n_-1)) = value;&lt;/P&gt;
&lt;P&gt;if done;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The assumptions can be relaxed, but would require changes to the program.&amp;nbsp; So if the conditions are actually more complex than what you have specified so far, you need to spell them out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;************ EDITED:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;Verified that these techniques work.&amp;nbsp; Sample test program:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&lt;FONT size="2"&gt;data &lt;/FONT&gt;&lt;FONT face="Lucida Console" size="2"&gt;test&lt;/FONT&gt;&lt;FONT size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;input c $char8.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;retain all;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;length all $ 24;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;substr(all, 1 + (_n_-1)*8) = c;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;datalines;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;abc&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;12345678&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;def&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;　&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;proc print; run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 15:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437550#M108970</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-15T15:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437556#M108974</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=;
%let server_log=&amp;amp;path./server.log;
%let program_name=start_flexi_dash;

%macro multiple_xml;

	data log_file(keep=txt);
		length org_txt $10000 txt $10000;
		infile "&amp;amp;server_log.";
		input;
		org_txt= _infile_;

		if index(org_txt,"Request body--&amp;gt;") &amp;gt; 0 then
			do;
				txt=substr(org_txt,index(org_txt,"Request body--&amp;gt;")+15,length(org_txt));
				output;
			end;
	run;

	proc sql noprint;
		select count(*) into :count from log_file;
	quit;

	%do i=1 %to &amp;amp;count;

		data _null_;
			set log_file;

			if _N_= &amp;amp;i then
				do;
					file "%sysfunc(pathname(work))/xml_temp.xml";
					put txt;
					call symput("pgm_name",substr(txt,2,find(txt,"&amp;gt;",2)-2 ));
				end;
		run;

		%if &amp;amp;pgm_name=&amp;amp;program_name %then
			%do;
				libname lib_xml xml  "%sysfunc(pathname(work))/xml_temp.xml" xmlconcatenate=yes;

				data xml_table;
					set lib_xml.parameters;
				run;

				proc transpose data=xml_table out=xml_trans;
					var _all_;
				run;

				data _null_;
					set xml_trans;
					call symputx(_NAME_,strip(col1),'g');
				run;

			%end;
	%end;
%mend;

%multiple_xml;

proc sql;
	create table vars as
		select name,value from dictionary.macros
			where scope eq 'GLOBAL';
quit;

proc sort data=vars;
	by name;
quit;

data macros(drop=value rename=(concatenate=value));
	length name $100 concatenate $32767;
	do until (last.name);
		set vars;
		by name;
		concatenate = concatenate||value;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;server.log file is below :&lt;/P&gt;&lt;PRE&gt;Request body--&amp;gt;&amp;lt;start_flexi_dash&amp;gt;&amp;lt;parameters&amp;gt;&amp;lt;MEASURES3&amp;gt;cnt_pol_COMBINE sum_pol_COMBINE cnt_pol_QA sum_pol_QA cnt_pol_FO sum_pol_FO cnt_pol_FACNP sum_pol_FACNP cnt_pol_PQS sum_pol_PQS cnt_pol_SURPLUS1 sum_pol_SURPLUS1 cnt_pol_SURPLUS2 sum_pol_SURPLUS2 cnt_pol_FACPROP sum_pol_FACPROP cnt_pol_OTHER sum_pol_OTHER cnt_ins_COMBINE sum_ins_COMBINE cnt_ins_QA sum_ins_QA cnt_ins_FO sum_ins_FO cnt_ins_FACNP sum_ins_FACNP cnt_ins_PQS sum_ins_PQS cnt_ins_SURPLUS1 sum_ins_SURPLUS1 cnt_ins_SURPLUS2 sum_ins_SURPLUS2 cnt_ins_FACPROP sum_ins_FACPROP cnt_ins_OTHER sum_ins_OTHER&amp;lt;/MEASURES3&amp;gt;&amp;lt;OE_ID_COUNT&amp;gt;1&amp;lt;/OE_ID_COUNT&amp;gt;&amp;lt;/parameters&amp;gt;&amp;lt;/start_flexi_dash&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my exact program will look like.&lt;/P&gt;&lt;P&gt;please copy the contents and save it as server.log and put the path of the file in the above of the sas program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ||&amp;nbsp;operator here returns null value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please check?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 13:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437556#M108974</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-02-15T13:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate variables with out removing leading and trailing spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437575#M108983</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/54638"&gt;@chithra&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; macros(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=b);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&amp;nbsp; length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; concatenate $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;100&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&amp;nbsp; do&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;until&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (last.a);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&amp;nbsp; &amp;nbsp; set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&amp;nbsp; &amp;nbsp; by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/FONT&gt;concatenate = cat(concatenate,b);&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&amp;nbsp; end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The above is a sample program where cat function is not working for me.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The CAT() function is doing what you told it to do.&amp;nbsp; You created CONCATENATE as length 100.&amp;nbsp; You that used CAT() function to create something that was LONGER than 100 characters and store it back into the 100 characters of CONCATENATE. Only the first 100 characters will fit so the value will always contain the 100 spaces that it started with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WHAT output do you want?&lt;/P&gt;
&lt;P&gt;Show both the input and output datasets in the form or working data steps.&lt;/P&gt;
&lt;P&gt;Please use the {i} or SAS Running Man icons to post code otherwise the forum editor will re-format the code and any spaces you are trying to show&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 13:42:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-variables-with-out-removing-leading-and-trailing/m-p/437575#M108983</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-15T13:42:20Z</dc:date>
    </item>
  </channel>
</rss>

