<?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: Many-to-Many merge situation with &amp;quot;multiple&amp;quot; key variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Many-to-Many-merge-situation-with-quot-multiple-quot-key/m-p/33369#M6505</link>
    <description>Possibly consider PROC FREQ with a CLASS ID X; and an OUTPUT statement but no VAR statement, and use the output variable _FREQ_ as your count of the unique ID and X combinations.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Tue, 22 Jul 2008 20:21:54 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2008-07-22T20:21:54Z</dc:date>
    <item>
      <title>Many-to-Many merge situation with "multiple" key variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Many-to-Many-merge-situation-with-quot-multiple-quot-key/m-p/33368#M6504</link>
      <description>I have another question, if I want to count the number of records in the group but the records have been defined with more than one key (by) variables (e.g. by id x instead of by id only), is there a way to adjust the following example code for a group of key variables to obtain that number (the count)?&lt;BR /&gt;
&lt;BR /&gt;
Example (only one key variable, id):&lt;BR /&gt;
&lt;BR /&gt;
data old;&lt;BR /&gt;
input id x;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 5&lt;BR /&gt;
1 7&lt;BR /&gt;
1 7&lt;BR /&gt;
2 1&lt;BR /&gt;
2 2&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
DATA new;&lt;BR /&gt;
Set old;&lt;BR /&gt;
by id;&lt;BR /&gt;
RETAIN count;&lt;BR /&gt;
IF first.ID THEN count=0;&lt;BR /&gt;
count = count + 1;&lt;BR /&gt;
IF last.ID THEN OUTPUT;&lt;BR /&gt;
KEEP ID count;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
The final idea is to obtain the number of many-to-many cases within a merge.  I want to identify how many cases (ids) are not unique (e.g. id=1 and x=7 in the previous example) in each data file (i.e. “MERGE statement has more than one data set with repeats of BY values.) to compute the total % of many-to-many cases in the merged file. &lt;BR /&gt;
&lt;BR /&gt;
Thanks

Message was edited by: Caramel</description>
      <pubDate>Tue, 22 Jul 2008 19:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Many-to-Many-merge-situation-with-quot-multiple-quot-key/m-p/33368#M6504</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-22T19:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Many-to-Many merge situation with "multiple" key variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Many-to-Many-merge-situation-with-quot-multiple-quot-key/m-p/33369#M6505</link>
      <description>Possibly consider PROC FREQ with a CLASS ID X; and an OUTPUT statement but no VAR statement, and use the output variable _FREQ_ as your count of the unique ID and X combinations.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 22 Jul 2008 20:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Many-to-Many-merge-situation-with-quot-multiple-quot-key/m-p/33369#M6505</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-07-22T20:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Many-to-Many merge situation with "multiple" key variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Many-to-Many-merge-situation-with-quot-multiple-quot-key/m-p/33370#M6506</link>
      <description>Adding X to the BY-clause, and using X with first./last. will do the trick as well:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
DATA new;&lt;BR /&gt;
   Set old;&lt;BR /&gt;
   by id &lt;B&gt;x&lt;/B&gt;;&lt;BR /&gt;
   RETAIN count;&lt;BR /&gt;
   IF first.&lt;B&gt;x&lt;/B&gt; THEN count=0;&lt;BR /&gt;
   count = count + 1;&lt;BR /&gt;
   IF last.&lt;B&gt;x&lt;/B&gt; THEN OUTPUT;&lt;BR /&gt;
   KEEP ID &lt;B&gt;x&lt;/B&gt; count;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Linus</description>
      <pubDate>Tue, 05 Aug 2008 12:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Many-to-Many-merge-situation-with-quot-multiple-quot-key/m-p/33370#M6506</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-08-05T12:44:25Z</dc:date>
    </item>
  </channel>
</rss>

