<?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: How to collapse multiple records into one in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95643#M20139</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks a lot, FredikE !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Apr 2013 16:06:24 GMT</pubDate>
    <dc:creator>LanMin</dc:creator>
    <dc:date>2013-04-05T16:06:24Z</dc:date>
    <item>
      <title>How to collapse multiple records into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95639#M20135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, all&lt;BR /&gt;I need your help programming the following&lt;BR /&gt;I want&lt;BR /&gt;1. combine multiple records into one if each record has the same GVKEY, SICS, and data_date, and use the sum of its sales as the sales for the single record and keep the first SID number.&lt;BR /&gt;2. Create a year variable based on data_date, if data_date month is before May 31, year variable=year (year variable)-1, otherwise year variable=year (year variable)- should I use month function and if then?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data have&lt;BR /&gt;GVKEY SID data_date SICS SALES&lt;BR /&gt;001004 1 19970531 4582 46.14&lt;BR /&gt;001004 2 19970531 4582 34.395&lt;BR /&gt;001004 1 19980531 4582 53.16&lt;BR /&gt;001004 2 19980531 4582 39.66&lt;BR /&gt;001005 3 19981031 3412 189.897&lt;BR /&gt;001005 4 19981031 3443 26.328&lt;BR /&gt;001005 5 19981031 5088 31.787&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data want&lt;BR /&gt;GVKEY SID data_date SICS SALES&lt;BR /&gt;001004 1 19970531 4582 92.82&lt;BR /&gt;001004 1 19980531 4582 80.535&lt;BR /&gt;001005 3 19981031 3412 189.897&lt;BR /&gt;001005 4 19981031 3443 26.328&lt;BR /&gt;001005 5 19981031 5088 31.787&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks !&lt;/P&gt;&lt;P&gt;Lan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Apr 2013 21:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95639#M20135</guid>
      <dc:creator>LanMin</dc:creator>
      <dc:date>2013-04-02T21:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to collapse multiple records into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95640#M20136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Some code like below should do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GVKEY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,SICS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,data_date format=date9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; , min(sid) as sid&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; , sum(sales) as sales &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; , year(intnx('year.6',data_date,0,'b')) as year&lt;/P&gt;&lt;P&gt;&amp;nbsp; from have&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by GVKEY,SICS,data_date&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 01:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95640#M20136</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-04-03T01:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to collapse multiple records into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95641#M20137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about this?&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt; length gvkey $6 sid 8 data_date $8 sics 8 sales 8;&lt;BR /&gt; input GVKEY SID data_date SICS SALES;&lt;/P&gt;&lt;P&gt; datalines;&lt;BR /&gt;001004 1 19970531 4582 46.14&lt;BR /&gt;001004 2 19970531 4582 34.395&lt;BR /&gt;001004 1 19980531 4582 53.16&lt;BR /&gt;001004 2 19980531 4582 39.66&lt;BR /&gt;001005 3 19981031 3412 189.897&lt;BR /&gt;001005 4 19981031 3443 26.328&lt;BR /&gt;001005 5 19981031 5088 31.787&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=a;&lt;BR /&gt; by GVKEY SICS data_date SID;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data b;&lt;BR /&gt; set a;&lt;BR /&gt; retain first_sid sales_sum;&lt;BR /&gt; by GVKEY SICS data_date SID;&lt;/P&gt;&lt;P&gt; if month(input(data_date,anydtdte.)) lt 5 then year = year(input(data_date,anydtdte.))-1;&lt;BR /&gt; else year = year (input(data_date,anydtdte.));&lt;BR /&gt; &lt;BR /&gt; if first.data_date then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; first_sid=sid;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; sales_sum = sales;&lt;BR /&gt; end;&lt;BR /&gt; else do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; sales_sum=sum(sales_sum,sales);&lt;BR /&gt; end;&lt;/P&gt;&lt;P&gt; if last.data_date then do;&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 14:48:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95641#M20137</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2013-04-03T14:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to collapse multiple records into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95642#M20138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks a lot, Patrick.&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; your help is very much aprpeciated!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 14:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95642#M20138</guid>
      <dc:creator>LanMin</dc:creator>
      <dc:date>2013-04-03T14:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to collapse multiple records into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95643#M20139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks a lot, FredikE !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 16:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-collapse-multiple-records-into-one/m-p/95643#M20139</guid>
      <dc:creator>LanMin</dc:creator>
      <dc:date>2013-04-05T16:06:24Z</dc:date>
    </item>
  </channel>
</rss>

