<?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 One-to-Many merge - how to limit the many back to one by an expression? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181223#M46156</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have simple one-to-many merge code like this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data baseball.playershighestsalary;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; merge baseball.players (in=InMaster) baseball.salaries (in=InSalaries);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; by playerID;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if InMaster and InSalaries;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; keep playerID birthYear birthMonth birthCountry salary;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Salaries dataset contains a row for each player for each year, so there are multiple rows for most players.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I simply want my merged dataset to include one row per player, including the max salary that player ever received (from the Salaries dataset). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to do it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm a newbie working on a final project in a SAS programming class, so I appreciate any solution or quick tip.&amp;nbsp; First time trying to get help on this community!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Oct 2014 17:07:53 GMT</pubDate>
    <dc:creator>StephenLaRoche</dc:creator>
    <dc:date>2014-10-11T17:07:53Z</dc:date>
    <item>
      <title>One-to-Many merge - how to limit the many back to one by an expression?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181223#M46156</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have simple one-to-many merge code like this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data baseball.playershighestsalary;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; merge baseball.players (in=InMaster) baseball.salaries (in=InSalaries);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; by playerID;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if InMaster and InSalaries;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; keep playerID birthYear birthMonth birthCountry salary;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Salaries dataset contains a row for each player for each year, so there are multiple rows for most players.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I simply want my merged dataset to include one row per player, including the max salary that player ever received (from the Salaries dataset). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to do it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm a newbie working on a final project in a SAS programming class, so I appreciate any solution or quick tip.&amp;nbsp; First time trying to get help on this community!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Oct 2014 17:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181223#M46156</guid>
      <dc:creator>StephenLaRoche</dc:creator>
      <dc:date>2014-10-11T17:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: One-to-Many merge - how to limit the many back to one by an expression?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181224#M46157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Limit dataset before merge to include the max salary or only one record per player&lt;/P&gt;&lt;P&gt;2. I don't think a data step merge can handle a many2many merge so you may want to use SQL&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Oct 2014 17:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181224#M46157</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-10-11T17:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: One-to-Many merge - how to limit the many back to one by an expression?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181225#M46158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have your Salaries data set sorted by "playerID Salary".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Amend your IF-condition to:&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;if inMaster &lt;/STRONG&gt;&lt;SPAN style="text-decoration: line-through;"&gt;and inSalaries&lt;/SPAN&gt;&lt;STRONG&gt; and last.playerID;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wouldn't use "and inSalaries" in your condition as this means you would remove players from your result for which there is no record in "Salaries".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Oct 2014 22:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181225#M46158</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-10-11T22:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: One-to-Many merge - how to limit the many back to one by an expression?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181226#M46159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table baseball.playershighestsalary as&lt;/P&gt;&lt;P&gt;select a.playerid,birthYear, birthMonth, birthCountry, b.salary&lt;/P&gt;&lt;P&gt;from baseball.players a left join (select playerid,max(salary) as salary from baseball.salaries group by playerid) b&lt;/P&gt;&lt;P&gt;on a.playerid=b.playerid;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Oct 2014 23:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181226#M46159</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-10-11T23:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: One-to-Many merge - how to limit the many back to one by an expression?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181227#M46160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If there was a tie for &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;max salary&lt;/SPAN&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;PRE&gt;data players;
input id ;
cards;
1 
2
3
;
run;
data salaries;
input id salaries;
cards;
1 23
1 43
2 43
2 21
3 45
4 34
;
run;
proc sort data=players;by id;run;
proc sort data=salaries;by id descending salaries;run;
data playershighestsalary;
&amp;nbsp; InMaster=0;
&amp;nbsp; merge players (in=InMaster) salaries ;
&amp;nbsp; by id;
&amp;nbsp; if InMaster ;
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;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Oct 2014 12:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/One-to-Many-merge-how-to-limit-the-many-back-to-one-by-an/m-p/181227#M46160</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-10-12T12:42:30Z</dc:date>
    </item>
  </channel>
</rss>

