<?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 with Some Missing Vars in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/504300#M134935</link>
    <description>&lt;P&gt;Here is the code I am trying to use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;sql&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;CREATE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;WANT &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SELECT&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DISTINCT&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Customer,&lt;/P&gt;&lt;P&gt;Item1,&lt;/P&gt;&lt;P&gt;Item2,&lt;/P&gt;&lt;P&gt;Item3,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(CATX (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;" "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Item1, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;", "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Item2, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;", "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Item3)) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Items&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Oct 2018 13:42:30 GMT</pubDate>
    <dc:creator>altijani</dc:creator>
    <dc:date>2018-10-15T13:42:30Z</dc:date>
    <item>
      <title>Concatenate with Some Missing Vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503842#M134717</link>
      <description>&lt;P&gt;Greetings Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Customer&lt;/TD&gt;&lt;TD&gt;Item1&lt;/TD&gt;&lt;TD&gt;Item2&lt;/TD&gt;&lt;TD&gt;Item3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;John&lt;/TD&gt;&lt;TD&gt;Shoes&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;David&lt;/TD&gt;&lt;TD&gt;Bags&lt;/TD&gt;&lt;TD&gt;Shirts&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Natasha&lt;/TD&gt;&lt;TD&gt;Shoes&lt;/TD&gt;&lt;TD&gt;Shirts&lt;/TD&gt;&lt;TD&gt;Bags&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to concatenate the items in one var as follows. Please note for some customers&amp;nbsp;it can go up to 10 items:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Customer&lt;/TD&gt;&lt;TD&gt;Items&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;John&lt;/TD&gt;&lt;TD&gt;Shoes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;David&lt;/TD&gt;&lt;TD&gt;Bags, Shirts&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Natasha&lt;/TD&gt;&lt;TD&gt;Shoes, Shirts, Bags&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 18:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503842#M134717</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2018-10-12T18:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate with Some Missing Vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503843#M134718</link>
      <description>&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;create table want as select&amp;nbsp;customer ,&amp;nbsp;cats(col1,col2,col3..) as concat_items from have;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;to automate:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select name&lt;BR /&gt;into :name_col separated by ','&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where upcase(memname) = 'have'&lt;BR /&gt;and upcase(name) like 'item%' ;&lt;BR /&gt;quit ;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as select customer , cats(&amp;amp;name_col.) as concat_items from have;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 19:07:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503843#M134718</guid>
      <dc:creator>sidpesar</dc:creator>
      <dc:date>2018-10-12T19:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate with Some Missing Vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503847#M134722</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Customer :$10.	(Item1	Item2	Item3) ($);
cards;
John	Shoes	 	 
David	Bags	Shirts	 
Natasha	Shoes	Shirts	Bags
;

data want;
set have;
length concat $50;
concat=catx(',',of item:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc sql does not support variable lists, nor array processing etc. These kind of operations are best performed in a datastep, plus I think you need catx instead of cats with delim ',' in between&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 19:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503847#M134722</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-12T19:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate with Some Missing Vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503849#M134723</link>
      <description>&lt;P&gt;See: &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;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be able to do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp; newValue = catx(', ', of item:);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Oct 2018 19:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503849#M134723</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-10-12T19:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate with Some Missing Vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503852#M134724</link>
      <description>&lt;P&gt;Thank you for your suggested code.&lt;BR /&gt;I tried these, and my issue the trailing commas.&lt;BR /&gt;&lt;BR /&gt;In case of Natasha, all is fine.&lt;BR /&gt;In case of David, there are 2 trailing commas&lt;BR /&gt;In case of Smith, there is a 1 trailing comma&lt;/P&gt;&lt;P&gt;Got my point?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;That what I would like to solve.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 19:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503852#M134724</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2018-10-12T19:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate with Some Missing Vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503867#M134733</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards truncover;
input Customer :$10.	(Item1	Item2	Item3) ($);
cards;
John	Shoes	 	 
David	Bags	Shirts	 
Natasha	Shoes	Shirts	Bags
;
data want;
set have;
array t(*) $20 item:;
length concat $50;
concat = peekc(addr (t[1]),20);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Oct 2018 19:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503867#M134733</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-12T19:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate with Some Missing Vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503868#M134734</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130872"&gt;@altijani&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your suggested code.&lt;BR /&gt;I tried these, and my issue the trailing commas.&lt;BR /&gt;&lt;BR /&gt;In case of Natasha, all is fine.&lt;BR /&gt;In case of David, there are 2 trailing commas&lt;BR /&gt;In case of Smith, there is a 1 trailing comma&lt;/P&gt;
&lt;P&gt;Got my point?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;That what I would like to solve.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show the code you used. There were several solutions suggested and without the actual code you used it is hard to recommend additional pieces.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 19:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503868#M134734</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-12T19:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate with Some Missing Vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503872#M134737</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   Item_combined=strip(tranwrd(catx(", ",Item1, Item2, Item3),"",""));
   drop Item1-Item3;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130872"&gt;@altijani&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this sas code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 19:42:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/503872#M134737</guid>
      <dc:creator>V_27</dc:creator>
      <dc:date>2018-10-12T19:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate with Some Missing Vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/504300#M134935</link>
      <description>&lt;P&gt;Here is the code I am trying to use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;sql&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;CREATE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;WANT &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SELECT&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DISTINCT&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Customer,&lt;/P&gt;&lt;P&gt;Item1,&lt;/P&gt;&lt;P&gt;Item2,&lt;/P&gt;&lt;P&gt;Item3,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(CATX (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;" "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Item1, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;", "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Item2, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;", "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, Item3)) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Items&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 13:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-with-Some-Missing-Vars/m-p/504300#M134935</guid>
      <dc:creator>altijani</dc:creator>
      <dc:date>2018-10-15T13:42:30Z</dc:date>
    </item>
  </channel>
</rss>

