<?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: User Written code to only display unique rows (based on two variables) in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123166#M1547</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to sort your data rather than use the notsorted option. &lt;/P&gt;&lt;P&gt;Because the period_yyyymm changes in between those variables SAS considers them different groups.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can sort either in the proc sql step with an order by or using a select distinct option. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 10 Nov 2012 20:56:56 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2012-11-10T20:56:56Z</dc:date>
    <item>
      <title>User Written code to only display unique rows (based on two variables)</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123165#M1546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A User Written transformation in DI Studio uses the following code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;proc sql;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; create table work.oppspartkap as&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; select polisenr, periode_yyyymm, oppspartkapital2 from &amp;amp;_input;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;quit;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;data &amp;amp;_output;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; set work.oppspartkap;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; by polisenr notsorted;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp;&amp;nbsp; if first.polisenr;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;run;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;/P&gt;&lt;P&gt;After running it, and applying a filter so that it only displays rows with polisenr 1, the work table looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG happy="" /&gt;&lt;/P&gt;&lt;P&gt;I need to edit the user written code so that identical rows, such as the three highlighted ones, only appear once. Not sure whether I should use "distinct" somewhere, "group by" somewhere, or something else. Kindly advise me, thanks. &lt;SPAN __jive_emoticon_name="_happy.gif'"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Nov 2012 20:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123165#M1546</guid>
      <dc:creator>TurnTheBacon</dc:creator>
      <dc:date>2012-11-10T20:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: User Written code to only display unique rows (based on two variables)</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123166#M1547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to sort your data rather than use the notsorted option. &lt;/P&gt;&lt;P&gt;Because the period_yyyymm changes in between those variables SAS considers them different groups.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can sort either in the proc sql step with an order by or using a select distinct option. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Nov 2012 20:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123166#M1547</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-11-10T20:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: User Written code to only display unique rows (based on two variables)</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123167#M1548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what you want to get rid of, or if maintaining the order is important (although, since you initially use proc sql, order can't be important).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As such, why not replace:&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data &amp;amp;_output;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; set work.oppspartkap;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; by polisenr notsorted;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; if first.polisenr;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;with:&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sort data=work.&lt;SPAN&gt;oppspartkap&lt;/SPAN&gt; out=&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;amp;_output nodupkey;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; polisenr periode_yyyymm oppspartkapital2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Nov 2012 20:59:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123167#M1548</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-10T20:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: User Written code to only display unique rows (based on two variables)</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123168#M1549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the feedback!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Arthur, using your suggested code I get the following output:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="2699" alt="Skjermbilde.PNG" class="jive-image" src="https://communities.sas.com/legacyfs/online/2699_Skjermbilde.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see there's some identical sets of polisenr&amp;amp;periode_yyyymm, but with different oppspartkapital2. The last oppspartkapital2 of each set is always correct. So, I think I need to add code that basically says "select last oppspartkapital2 for each distinct polisenr&amp;amp;periode_yyyymm". I'd appreciate some advice on this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the current code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;proc sql;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; create table work.oppspartkap as&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; select polisenr, periode_yyyymm, oppspartkapital2 from &amp;amp;_input;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;quit;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;proc sort data=work.oppspartkap out=&amp;amp;_output nodupkey;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by polisenr periode_yyyymm oppspartkapital2;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It doesn't matter to me if I use proc sql or data step.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Nov 2012 21:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123168#M1549</guid>
      <dc:creator>TurnTheBacon</dc:creator>
      <dc:date>2012-11-10T21:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: User Written code to only display unique rows (based on two variables)</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123169#M1550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should only use a User Written Transformation in DI Studio if there is no standard transformation available doing the job for you. In your case you can use the SQL Join transformation to get the job done. Set it up that it generates code as shown below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create view want as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; polisenr,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; period,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; max(OppspartKapital2) as OppspartKapital2&lt;/P&gt;&lt;P&gt;&amp;nbsp; from have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by polisenr, period&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code as above will deal with duplicates as well as select the "correct" value if there are "duplicates" with different OppspartKapital2 values (just selecting the highest value).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will have to ask yourself if it's o.k. that you get such data in first place or if you eventually should implement a Validation transformation somewhere upstream in the process to cleanse the data and to move "wrong" data to Error and Exception tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Patrick Matter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Nov 2012 22:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123169#M1550</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2012-11-10T22:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: User Written code to only display unique rows (based on two variables)</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123170#M1551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not versed in DI studio, thus I'm not sure what your best route is.&amp;nbsp; However, since you asked, a datastep at the end will do what you ask, namely:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data &amp;amp;_output;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; set data &amp;amp;_output;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; by polisenr periode_yyyymm;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; if last.&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;periode_yyyymm&lt;/SPAN&gt;;&lt;/P&gt;&lt;P style="padding: 0px 0px 0px 60px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Nov 2012 22:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/User-Written-code-to-only-display-unique-rows-based-on-two/m-p/123170#M1551</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-10T22:25:26Z</dc:date>
    </item>
  </channel>
</rss>

