<?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 PROC codes for merging tables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50207#M13657</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Lets call your two tables DONATIONS and DONORS.&lt;/P&gt;&lt;P&gt;Merge by donor id.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data details ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge donors donations ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by donor_id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use PROC SUMMARY to calculate your statistics.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data=details ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by donor_id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var donation_amt donation_date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output out=summary sum(donation_amt)=total min(donation_date)=first max(donation_date)=last n=number ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might want to reverse the steps and get the summary first and then merge that with the donor list to get the name, city etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Feb 2012 12:03:51 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2012-02-09T12:03:51Z</dc:date>
    <item>
      <title>PROC codes for merging tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50206#M13656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a data set as described below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="3" cellspacing="0" class="jiveBorder" style="width: 100%; border: 1px solid #000000;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;donor id&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;donation amt&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;donation date&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;payment type&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;appeal id&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;001234&lt;/TD&gt;&lt;TD&gt;£20&lt;/TD&gt;&lt;TD&gt;26/11/2005&lt;/TD&gt;&lt;TD&gt;direct debit&lt;/TD&gt;&lt;TD&gt;HHU&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;001234&lt;/TD&gt;&lt;TD&gt;£15&lt;/TD&gt;&lt;TD&gt;28/12/2006&lt;/TD&gt;&lt;TD&gt;cash&lt;/TD&gt;&lt;TD&gt;HHI&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;001236&lt;/TD&gt;&lt;TD&gt;£10&lt;/TD&gt;&lt;TD&gt;16/8/2007&lt;/TD&gt;&lt;TD&gt;direct debit&lt;/TD&gt;&lt;TD&gt;HHJ&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1.First, i want to merge data from another table (which has same donor id but with their&amp;nbsp; age, city and gender) to the above&lt;/P&gt;&lt;P&gt;2.Then&amp;nbsp; Create a table that has the total amount donated by each donor id; the first date of donation; last date of donation; the number of times they have donated(how many times they have donated from the first date of donation) exclude, payment type and appeal id from the output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Feb 2012 11:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50206#M13656</guid>
      <dc:creator>Relle</dc:creator>
      <dc:date>2012-02-09T11:49:48Z</dc:date>
    </item>
    <item>
      <title>PROC codes for merging tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50207#M13657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Lets call your two tables DONATIONS and DONORS.&lt;/P&gt;&lt;P&gt;Merge by donor id.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data details ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge donors donations ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by donor_id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use PROC SUMMARY to calculate your statistics.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data=details ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by donor_id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var donation_amt donation_date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output out=summary sum(donation_amt)=total min(donation_date)=first max(donation_date)=last n=number ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might want to reverse the steps and get the summary first and then merge that with the donor list to get the name, city etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Feb 2012 12:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50207#M13657</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-02-09T12:03:51Z</dc:date>
    </item>
    <item>
      <title>PROC codes for merging tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50208#M13658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Hi Tom thanks for the helpful reply. I receive an error when i run the merge query, because some of the donor ids have letters in them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"ERROR: variable donor id has been defined as both character and numeric"&lt;/P&gt;&lt;P&gt;How can i rectify this? thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Feb 2012 12:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50208#M13658</guid>
      <dc:creator>Relle</dc:creator>
      <dc:date>2012-02-09T12:20:37Z</dc:date>
    </item>
    <item>
      <title>PROC codes for merging tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50209#M13659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do proc contents for both datasets and find out which variable has a numeric value for Donar_id. Convert that variable in to charactor using PUT function.&lt;/P&gt;&lt;P&gt;specify the variable length same as the second dataset Donar_ID variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Feb 2012 12:41:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50209#M13659</guid>
      <dc:creator>Pallav</dc:creator>
      <dc:date>2012-02-09T12:41:39Z</dc:date>
    </item>
    <item>
      <title>PROC codes for merging tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50210#M13660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The ERROR information has shown you that the donor_id in these two datasets has different type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data one;
input id $&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt : dollar20.&amp;nbsp; date : ddmmyy10.&amp;nbsp; type &amp;amp; $20.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;appeal&amp;nbsp; $;
format date ddmmyy10.;
cards;
001234 20 26/11/2005 direct debit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HHU
001234 15 28/12/2006 cash&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HHI
001236&amp;nbsp; 10 16/8/2007 direct debit&amp;nbsp;&amp;nbsp;&amp;nbsp; HHJ
;
run;
data two;
input id $ age city $ gender $;
cards;
001234 23 nv f
001236 45 bs m
;
run; 

proc sort data=one;by id date;run;
data temp;
 set one;
 by id;
 retain n sum first_date;
 if first.id then do;first_date=date; n=0;sum=0;end;
 n+1;sum+amt;
 if last.id then do;last_date=date;output;end;
 format first_date last_date ddmmyy10.;
 drop amt type appeal date;
run;

proc sort data=two;by id;run;
data want;
 merge temp two;
 by id;
run;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Feb 2012 08:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50210#M13660</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-02-10T08:38:09Z</dc:date>
    </item>
    <item>
      <title>PROC codes for merging tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50211#M13661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thank you Ksharp,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just a couple of questions as i am not familiar with most of the proc statements.&lt;/P&gt;&lt;P&gt;First the example table i have used is just a snapshot of the whole data set. There are actually 375, 000 records of data so will&amp;nbsp; the 'cards' function be applicable in this case? i'll like to use all the ids present in the data set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second when i try to run a proc summary statement, i receive an error to say the data is not sorted in ascending order of id.How can i rectify this?&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Feb 2012 11:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50211#M13661</guid>
      <dc:creator>Relle</dc:creator>
      <dc:date>2012-02-14T11:06:00Z</dc:date>
    </item>
    <item>
      <title>PROC codes for merging tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50212#M13662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Cards is just used to load some data entered within the code, this is n/a for your situation, just for the demo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SUMMARY with BY (and most other PROCs) assume that data is pre-sorted.&lt;/P&gt;&lt;P&gt;So, you can either sort your data first on the BY variable you wish to group by, or use CLASS instead (does not require input data to be sorted), or use PROC SQL GROUP BY.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Feb 2012 14:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50212#M13662</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2012-02-14T14:03:03Z</dc:date>
    </item>
    <item>
      <title>PROC codes for merging tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50213#M13663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;LinusH has already respond your questions.&lt;/P&gt;&lt;P&gt;cards is only for demo. If you already have one two datasets at work library, then remove &lt;/P&gt;&lt;P&gt;these two cards.&amp;nbsp; And don't forget make sure the type of id has the same type in these two datasets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Feb 2012 02:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50213#M13663</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-02-15T02:02:16Z</dc:date>
    </item>
    <item>
      <title>PROC codes for merging tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50214#M13664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks for the clarification&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Feb 2012 12:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-codes-for-merging-tables/m-p/50214#M13664</guid>
      <dc:creator>Relle</dc:creator>
      <dc:date>2012-02-15T12:15:07Z</dc:date>
    </item>
  </channel>
</rss>

