<?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 multiple rows into a single value in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502934#M743</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/171358"&gt;@mkaur89&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Adding the commas did not really help. It just added that many comes to the front of the row. I would want the commas separating the prefixes.&amp;nbsp;&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="Capture.JPG" style="width: 216px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23920iF56A4BCDC1659E7D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My company is in the process of converting all of our data extraction queries to SAS. A large number of our queries are in Hyperion&amp;nbsp;and I've come across this scenario in multiple queries. Our data in being extracted from a teradata server so depending on the filters i input i have no idea how many results i will end up getting.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SHOW the code you actually ran.&lt;/P&gt;
&lt;P&gt;The presence of many commas as you show indicates that your field has missing values for some of the data. So you need to decide what to do about the missing values. Test if missing and not concatenate would be one option but you know more of what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way to find out how many levels of your variable you may need:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   select max(countage) as maxvars
   from (select sex, count(age) as countage from 
            (select distinct sex,age from sashelp.class)
         group by sex
        )
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;Maxvars would have the maximum count of the variable age associated with the different levels of the Sex variable in this set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Oct 2018 22:59:26 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-10-09T22:59:26Z</dc:date>
    <item>
      <title>Concatenate multiple rows into a single value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502886#M723</link>
      <description>&lt;P&gt;Hi there!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having a problem with concatenating a series of rows into a single row based on a group within a SAS dataset.&lt;/P&gt;&lt;P&gt;Basically a simplified version of what I want is to be able to is start with something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.Renewal AS&lt;/P&gt;&lt;P&gt;SELECT&lt;BR /&gt;/* Policy Number */&lt;BR /&gt;(CAT(t1.BRANCH_NBR, t1.DEC_NBR, t1.PAK_POLCY_NBR)) AS 'Policy Number'n,&lt;BR /&gt;t1.POLCY_PREFX_ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this will give something like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 202px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23918iC17DC8D05B0A6E30/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 244px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23919i2200B0A95C2053FF/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I looked at this post and it has the basic concept of what i'm wanting, but not exactly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-rows-into-a-single-value/td-p/132882" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-rows-into-a-single-value/td-p/132882&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 20:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502886#M723</guid>
      <dc:creator>mkaur89</dc:creator>
      <dc:date>2018-10-09T20:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate multiple rows into a single value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502891#M725</link>
      <description>You cannot do this easily in SQL, you need a data step, and the solution is the same as in the example you've linked to. SQL doesn't absolutely maintain row orders, so that's one reason not to use SQL. If you're using a server, you can use Pass Through and either a PIVOT or SUMMARIZE task to achieve the same result but that would depend on your RDBMS.</description>
      <pubDate>Tue, 09 Oct 2018 20:36:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502891#M725</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-09T20:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate multiple rows into a single value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502909#M735</link>
      <description>&lt;P&gt;This is not a job for PROC SQL. Do like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input PolicyNumber $ Policy_Prefix_ID $;
datalines;
123458 ABC
123458 BCD
123458 CDF
199564 ABC
199564 WFD
199564 GHB
185284 XXX
153485 ABC
;

data want;
   set have(rename=(Policy_Prefix_ID=ppid));
   length Policy_Prefix_ID $100;
   by PolicyNumber notsorted;

   if first.PolicyNumber then Policy_Prefix_ID="";

   Policy_Prefix_ID=cats(Policy_Prefix_ID, ppid);

   if last.PolicyNumber;
   retain Policy_Prefix_ID;
   drop ppid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Oct 2018 20:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502909#M735</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-10-09T20:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate multiple rows into a single value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502913#M737</link>
      <description>&lt;P&gt;I thing instead of&lt;/P&gt;
&lt;PRE&gt;Policy_Prefix_ID=cats(Policy_Prefix_ID, ppid);
&lt;/PRE&gt;
&lt;P&gt;that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Policy_Prefix_ID=catx(',',Policy_Prefix_ID, ppid);
&lt;/PRE&gt;
&lt;P&gt;comes closer to requested result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you should have some idea how many items and their lengths to set the length of the result. Don't forget to count the commas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And again, why? If this for anything more than a marginally hard to read report column further processing is likely to be a headache.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 21:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502913#M737</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-09T21:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate multiple rows into a single value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502919#M739</link>
      <description>&lt;P&gt;I'm not sure how to go about doing what you just suggested. It seems like i would have to type out every results. The way i am getting my data is through a teradata server and it could be over a 100,000 results and i don't know how many prefix id's a policy might have. Knowing this information, would you still suggest using this method or should I focus on maybe creating a pivot? I'm really new to SAS (just started learning 2 weeks ago) and I am imagining a pivot similar to which i can create in excel. However, even an excel pivot can not get me all of the rows into a single cell.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm used to using Hyperion and i was able to compute it using a simple formula:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sum(Policy_Prefx_ID, Policy_Number)&amp;nbsp;&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>Tue, 09 Oct 2018 22:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502919#M739</guid>
      <dc:creator>mkaur89</dc:creator>
      <dc:date>2018-10-09T22:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate multiple rows into a single value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502921#M740</link>
      <description>&lt;P&gt;Adding the commas did not really help. It just added that many comes to the front of the row. I would want the commas separating the prefixes.&amp;nbsp;&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="Capture.JPG" style="width: 216px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23920iF56A4BCDC1659E7D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My company is in the process of converting all of our data extraction queries to SAS. A large number of our queries are in Hyperion&amp;nbsp;and I've come across this scenario in multiple queries. Our data in being extracted from a teradata server so depending on the filters i input i have no idea how many results i will end up getting.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 22:16:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502921#M740</guid>
      <dc:creator>mkaur89</dc:creator>
      <dc:date>2018-10-09T22:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate multiple rows into a single value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502934#M743</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/171358"&gt;@mkaur89&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Adding the commas did not really help. It just added that many comes to the front of the row. I would want the commas separating the prefixes.&amp;nbsp;&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="Capture.JPG" style="width: 216px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23920iF56A4BCDC1659E7D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My company is in the process of converting all of our data extraction queries to SAS. A large number of our queries are in Hyperion&amp;nbsp;and I've come across this scenario in multiple queries. Our data in being extracted from a teradata server so depending on the filters i input i have no idea how many results i will end up getting.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SHOW the code you actually ran.&lt;/P&gt;
&lt;P&gt;The presence of many commas as you show indicates that your field has missing values for some of the data. So you need to decide what to do about the missing values. Test if missing and not concatenate would be one option but you know more of what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way to find out how many levels of your variable you may need:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   select max(countage) as maxvars
   from (select sex, count(age) as countage from 
            (select distinct sex,age from sashelp.class)
         group by sex
        )
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;Maxvars would have the maximum count of the variable age associated with the different levels of the Sex variable in this set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 22:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502934#M743</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-09T22:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate multiple rows into a single value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502965#M745</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/171358"&gt;@mkaur89&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Adding the commas did not really help. It just added that many comes to the front of the row. I would want the commas separating the prefixes.&amp;nbsp;&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="Capture.JPG" style="width: 216px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23920iF56A4BCDC1659E7D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My company is in the process of converting all of our data extraction queries to SAS. A large number of our queries are in Hyperion&amp;nbsp;and I've come across this scenario in multiple queries. Our data in being extracted from a teradata server so depending on the filters i input i have no idea how many results i will end up getting.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The approach used in the data doesn't care how many records there are for each ID. It does it automatically. Did you try any of those solutions, and if you did, please post the code that didn't work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're just learning, try it with example data first, even just running the code/solution from the other threads and then figure out how your data is different than the example to figure out where the issue is.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 03:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Concatenate-multiple-rows-into-a-single-value/m-p/502965#M745</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-10T03:30:03Z</dc:date>
    </item>
  </channel>
</rss>

