<?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: duplicating rows by conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/duplicating-rows-by-conditions/m-p/707008#M217066</link>
    <description>What if there's a tie in the most common, ie I took three different extra courses at three different institutions? It almost looks like you want the cross product instead. &lt;BR /&gt;&lt;BR /&gt;Something like this may work. Do you need the years to match as well? If so, you would add a condition that t1.year=t2.year as well to the query.&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as &lt;BR /&gt;select t1.id, t1.prov, t1.year, t1.school, t2.school as school2&lt;BR /&gt;from t1, t2&lt;BR /&gt;where t1.id=t2.id &lt;BR /&gt;and t1.school &amp;gt; t2.school &lt;BR /&gt;and t1.year=t2.year&lt;BR /&gt;order by id, prov, year, school;&lt;BR /&gt;quit;</description>
    <pubDate>Fri, 18 Dec 2020 17:01:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-12-18T17:01:58Z</dc:date>
    <item>
      <title>duplicating rows by conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/duplicating-rows-by-conditions/m-p/707004#M217064</link>
      <description>&lt;P&gt;Hi SAS experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to know, for a given year&amp;amp;province&amp;amp;school, what’s the most common &lt;STRONG&gt;other&lt;/STRONG&gt; school that people enrol, when they enrolled in multiple school in the same time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A quick example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&g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D&gt;&lt;TD&gt;&lt;P&gt;35&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2009&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;105&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;104&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the table “want”, there is an additional column “school2” to record the other school that this person enrolled in a given year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greatly appreciate for any hints!&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Fri, 18 Dec 2020 16:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/duplicating-rows-by-conditions/m-p/707004#M217064</guid>
      <dc:creator>nash_zheng</dc:creator>
      <dc:date>2020-12-18T16:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: duplicating rows by conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/duplicating-rows-by-conditions/m-p/707005#M217065</link>
      <description>&lt;P&gt;Please define "most common" and provide an example that actually uses a "most common". What your current example shows for output is "any other".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide data in the form of a data step if you actually want working code. The "example" data does not lend itself to pasting into an editor and attempting to write code to read it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 16:55:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/duplicating-rows-by-conditions/m-p/707005#M217065</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-18T16:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: duplicating rows by conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/duplicating-rows-by-conditions/m-p/707008#M217066</link>
      <description>What if there's a tie in the most common, ie I took three different extra courses at three different institutions? It almost looks like you want the cross product instead. &lt;BR /&gt;&lt;BR /&gt;Something like this may work. Do you need the years to match as well? If so, you would add a condition that t1.year=t2.year as well to the query.&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as &lt;BR /&gt;select t1.id, t1.prov, t1.year, t1.school, t2.school as school2&lt;BR /&gt;from t1, t2&lt;BR /&gt;where t1.id=t2.id &lt;BR /&gt;and t1.school &amp;gt; t2.school &lt;BR /&gt;and t1.year=t2.year&lt;BR /&gt;order by id, prov, year, school;&lt;BR /&gt;quit;</description>
      <pubDate>Fri, 18 Dec 2020 17:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/duplicating-rows-by-conditions/m-p/707008#M217066</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-12-18T17:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: duplicating rows by conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/duplicating-rows-by-conditions/m-p/707745#M217342</link>
      <description>&lt;P&gt;This computes an &lt;A href="https://en.wikipedia.org/wiki/Adjacency_matrix" target="_self"&gt;adjacency matrix&lt;/A&gt;&amp;nbsp;where the vertex on the graph of schools is the count of how many times a student enrolled into school X and school Y in the same year.&amp;nbsp;From this you want to get a table listing vertices that have the largest "popularity-value" from each node/"school" in the graph.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as
    select Distinct 
           t1.school as school1, 
           t2.school as school2, 
           count(*) as count
      from have t1, have t2
      where t1.id=t2.id
        and t1.year=t2.year
        and t1.school &amp;gt; t2.school
      group by t1.school,t2.school
;
quit;

data want;
  set want want (rename=(school1=school2 school2=school1));
proc  sort;
  by school1 descending count;
proc  sort nodupkey;
  by school1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I once took this free EdX internet course on Excel and data analysis with &lt;A class="name font-weight-bold" href="https://www.edx.org/bio/felienne-hermans" target="_blank" rel="noopener"&gt;Felienne Hermans&lt;/A&gt;&amp;nbsp;from the Delft University of Technology, Netherlands.&amp;nbsp; She taught her students,&amp;nbsp;using data yanked from IMDB.com, to calculate an actor's &lt;A href="https://en.wikipedia.org/wiki/Six_Degrees_of_Kevin_Bacon" target="_self"&gt;Bacon number&lt;/A&gt;&amp;nbsp;using similar math to this.&amp;nbsp; It was fun.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 20:11:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/duplicating-rows-by-conditions/m-p/707745#M217342</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2020-12-22T20:11:10Z</dc:date>
    </item>
  </channel>
</rss>

