<?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: summarize data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/458094#M116227</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;i tried the code , its giving the output like below , but we need the 5th observation only for Id 3 (i.e&amp;nbsp;&lt;SPAN&gt;3 bang,bbsr,hyd)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;please suggest&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;also as there are many datasets so i am appendeing all the datsets , then sort it by Id and then i am applying&amp;nbsp; the code&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 del&lt;BR /&gt;2 mum&lt;BR /&gt;3 bang&lt;BR /&gt;3 bang,bbsr&lt;BR /&gt;3 bang,bbsr,hyd&lt;BR /&gt;4 cal&lt;BR /&gt;5 pun&lt;BR /&gt;6 che&lt;/P&gt;</description>
    <pubDate>Fri, 27 Apr 2018 11:47:57 GMT</pubDate>
    <dc:creator>soham_sas</dc:creator>
    <dc:date>2018-04-27T11:47:57Z</dc:date>
    <item>
      <title>summarize data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/457874#M116147</link>
      <description>&lt;P&gt;Hi i have 3 tables called one two and three (in realtime i have around 40 to 50 different tables)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have to summarize these tables based on the ID as the key variable , like ID 3 is in all the table with different dept name, so in the final summarized table the dept for Id 3 should be all the 3 dept separated by a comma (,)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data i have below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input id dept$;&lt;BR /&gt;cards;&lt;BR /&gt;1 del&lt;BR /&gt;2 mum&lt;BR /&gt;3 bang&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;input id dept$;&lt;BR /&gt;cards;&lt;BR /&gt;3 bbsr&lt;BR /&gt;4 cal&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data three;&lt;BR /&gt;input id dept$;&lt;BR /&gt;cards;&lt;BR /&gt;5 pun&lt;BR /&gt;3 hyd&lt;BR /&gt;6 che&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data i want :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;dept&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;del&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;mum&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;bang ,Hyd ,bbsr&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;cal&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;pun&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;che&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 18:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/457874#M116147</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2018-04-26T18:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: summarize data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/457925#M116167</link>
      <description>&lt;P&gt;since no duplicates,&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. do a one to one merge&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. catx with delim&lt;/P&gt;&lt;P&gt;3. keep the vars you want in final and you are done&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 19:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/457925#M116167</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-26T19:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: summarize data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/457928#M116169</link>
      <description>&lt;P&gt;Here's an illustration of two different methods:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create sample data for demonstration;
data have;
    infile cards dlm='09'x;
    input OrgID Product $   States $;
    cards;
1   football    DC
1   football    VA
1   football    MD
2   football    CA
3   football    NV
3   football    CA
;
run;

*Sort - required for both options;
proc sort data=have;
    by orgID;
run;

**********************************************************************;
*Use RETAIN and BY group processing to combine the information;
**********************************************************************;
data want_option1;
    set have;
    by orgID;
    length combined $100.;
    retain combined;

    if first.orgID then
        combined=states;
    else
        combined=catx(', ', combined, states);

    if last.orgID then
        output;
run;

**********************************************************************;
*Transpose it to a wide format and then combine into a single field;
**********************************************************************;
proc transpose data=have out=wide prefix=state_;
    by orgID;
    var states;
run;

data want_option2;
    set wide;
    length combined $100.;
    combined=catx(', ', of state_:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93889"&gt;@soham_sas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi i have 3 tables called one two and three (in realtime i have around 40 to 50 different tables)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i have to summarize these tables based on the ID as the key variable , like ID 3 is in all the table with different dept name, so in the final summarized table the dept for Id 3 should be all the 3 dept separated by a comma (,)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data i have below&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data one;&lt;BR /&gt;input id dept$;&lt;BR /&gt;cards;&lt;BR /&gt;1 del&lt;BR /&gt;2 mum&lt;BR /&gt;3 bang&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data two;&lt;BR /&gt;input id dept$;&lt;BR /&gt;cards;&lt;BR /&gt;3 bbsr&lt;BR /&gt;4 cal&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data three;&lt;BR /&gt;input id dept$;&lt;BR /&gt;cards;&lt;BR /&gt;5 pun&lt;BR /&gt;3 hyd&lt;BR /&gt;6 che&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data i want :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;id&lt;/TD&gt;
&lt;TD&gt;dept&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;del&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;mum&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;bang ,Hyd ,bbsr&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;cal&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;pun&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;che&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 19:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/457928#M116169</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-26T19:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: summarize data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/457944#M116176</link>
      <description>&lt;P&gt;First, sort all three data sets by ID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure why you want Hyd as the middle value instead of the last value (or if that is just a mistake).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After sorting, you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set one two three;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;length all_depts $ 100;&lt;/P&gt;
&lt;P&gt;if first.id then all_depts = dept;&lt;/P&gt;
&lt;P&gt;else all_depts = catx(', ', all_depts, dept);&lt;/P&gt;
&lt;P&gt;if last.id;&lt;/P&gt;
&lt;P&gt;drop dept;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice that you need a new, longer variable to hold the full set of characters.&amp;nbsp; If you want to, you could add this as the final statement (before the run statement):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rename all_depts = dept;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want Hyd as the middle value you would need to change the SET statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set one three two;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, note that this is probably a bad idea.&amp;nbsp; The vast majority of the time it will be easier to use the data in its original form.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 20:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/457944#M116176</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-26T20:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: summarize data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/458094#M116227</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;i tried the code , its giving the output like below , but we need the 5th observation only for Id 3 (i.e&amp;nbsp;&lt;SPAN&gt;3 bang,bbsr,hyd)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;please suggest&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;also as there are many datasets so i am appendeing all the datsets , then sort it by Id and then i am applying&amp;nbsp; the code&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 del&lt;BR /&gt;2 mum&lt;BR /&gt;3 bang&lt;BR /&gt;3 bang,bbsr&lt;BR /&gt;3 bang,bbsr,hyd&lt;BR /&gt;4 cal&lt;BR /&gt;5 pun&lt;BR /&gt;6 che&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 11:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/458094#M116227</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2018-04-27T11:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: summarize data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/458101#M116230</link>
      <description>&lt;P&gt;That would happen if you leave out the statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if last.id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do have further issues, be sure to post the log.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 12:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-data/m-p/458101#M116230</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-27T12:17:24Z</dc:date>
    </item>
  </channel>
</rss>

