<?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: Concatenating strings from multiple rows into single row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549308#M152394</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Can you please explain why don;t we need to use first statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For one thing it references a variable that does not exist in your example data. The FIRST. syntax also expects that the variable appears on a BY statement. Since you don't have a variable month_Yadua in the example we get an uninitialized variable note and has no effect on the output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Apr 2019 15:25:33 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-04-08T15:25:33Z</dc:date>
    <item>
      <title>Concatenating strings from multiple rows into single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549104#M152324</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I want to&amp;nbsp;Concatenating strings from multiple rows into single row in table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I expect to get in last row under &lt;FONT class="font5"&gt;months_list column the value &amp;nbsp;1808+1809+1810+1811+1812+1901.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;But I don't get this desired result.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May anyone help and explain what is the problem with code?&lt;FONT class="font0"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1;
input month $;
cards;
1808
1809
1810
1811
1812
1901
;
run;


data tbl2;
  length months_list  $ 50;
  set tbl2;
  by month;
  retain months_list;
  if first.month_Yadua then months_list = month;
  else months_list = catx('+', months_list, month);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 11:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549104#M152324</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-04-07T11:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings from multiple rows into single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549105#M152325</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1;
input month $;
cards;
1808
1809
1810
1811
1812
1901
;
run;


data tbl2;
  length months_list  $ 50;
  set tbl1;
  retain months_list;
  months_list = catx('+', months_list, month);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Apr 2019 11:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549105#M152325</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-07T11:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings from multiple rows into single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549106#M152326</link>
      <description>&lt;P&gt;Can you please explain why don;t we need to use first statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 11:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549106#M152326</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-04-07T11:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings from multiple rows into single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549107#M152327</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Can you please explain why don;t we need to use first statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Because you do not want to treat every month as a single group. You want to concatenate ALL months.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 11:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549107#M152327</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-07T11:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings from multiple rows into single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549120#M152330</link>
      <description>&lt;P&gt;Please pay attention to notes, to your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; tbl2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token function"&gt;length&lt;/SPAN&gt; months_list  &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;50&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; tbl2&lt;SPAN class="token punctuation"&gt;;   /* &amp;lt;&amp;lt;&amp;lt;&amp;lt; should be tbl1, same name as created in previous step */ &lt;/SPAN&gt;
  &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;month&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;retain&lt;/SPAN&gt; months_list&lt;SPAN class="token punctuation"&gt;;   /* &amp;lt;&amp;lt;&amp;lt; default value is an empty field, so no need to assign&lt;BR /&gt;&lt;/SPAN&gt;                            specific value first time */
  &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;month_Yadua &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; months_list &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;month&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;  /* month_Yadua is an undefined variable&lt;BR /&gt;&lt;/SPAN&gt;                                                     you could use first.month (asyou defined by month )&lt;BR /&gt;                                                     but then&lt;BR /&gt;                                                     each row will be "first" and no concatenation */ 
  &lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; months_list &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;catx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'+'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; months_list&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;month&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Apr 2019 16:40:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549120#M152330</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-04-07T16:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings from multiple rows into single row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549308#M152394</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Can you please explain why don;t we need to use first statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For one thing it references a variable that does not exist in your example data. The FIRST. syntax also expects that the variable appears on a BY statement. Since you don't have a variable month_Yadua in the example we get an uninitialized variable note and has no effect on the output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 15:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings-from-multiple-rows-into-single-row/m-p/549308#M152394</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-08T15:25:33Z</dc:date>
    </item>
  </channel>
</rss>

