<?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: Proc sort with nodupkey in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416145#M280221</link>
    <description>&lt;P&gt;HAVING in PROC SQL can select duplicates if they are present in the data.&lt;/P&gt;</description>
    <pubDate>Sat, 25 Nov 2017 16:37:23 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-11-25T16:37:23Z</dc:date>
    <item>
      <title>Proc sort with nodupkey in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416136#M280214</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I am trying put all the sas datastep into proc sql steps. below is the question and the scenario.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I have one proc sql statement connected to oracle(though i have not mentioned oracle connection below)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table a as select *from new;
quit;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Then two proc sort statement based on above dataset a.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = a;
by promo descending flag;
run;
proc sort data =a nodupkey out =new1;
by promo;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; Now I want to do these two proc sort statements inside proc sql statement itself.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 13:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416136#M280214</guid>
      <dc:creator>ganandlife</dc:creator>
      <dc:date>2017-11-25T13:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort with nodupkey in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416137#M280215</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/179487"&gt;@ganandlife&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I am trying put all the sas datastep into proc sql steps.b&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why? The functions in a data step and the functions in SQL do not completely overlap, some things won't be possible in a data step and some things won't be possible in PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&amp;nbsp;&amp;nbsp; Then two proc sort statement based on above dataset a.
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = a;
by promo descending flag;
run;
proc sort data =a nodupkey out =new1;
by promo;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; Now I want to do these two proc sort statements inside proc sql statement itself.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This isn't clear ... it sounds like you want to run PROC SORT inside SQL which isn't possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the SORT clause in PROC SQL, is that what you mean?&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 15:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416137#M280215</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-11-25T15:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort with nodupkey in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416138#M280216</link>
      <description>Nope.....First i need to sort by promo and descending flag, then get the highest flag for each promo and send the remaining to new dataset new 1 –. I want to do all these in single proc sql statement</description>
      <pubDate>Sat, 25 Nov 2017 15:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416138#M280216</guid>
      <dc:creator>ganandlife</dc:creator>
      <dc:date>2017-11-25T15:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort with nodupkey in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416139#M280217</link>
      <description>&lt;P&gt;You’re using pass through so you need Oracle SQL not SAS SQL, correct?&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 16:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416139#M280217</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-25T16:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort with nodupkey in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416142#M280218</link>
      <description>yes</description>
      <pubDate>Sat, 25 Nov 2017 16:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416142#M280218</guid>
      <dc:creator>ganandlife</dc:creator>
      <dc:date>2017-11-25T16:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort with nodupkey in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416143#M280219</link>
      <description>&lt;P&gt;Sounds like you want to use the HAVING clause in PROC SQL&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 16:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416143#M280219</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-11-25T16:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort with nodupkey in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416144#M280220</link>
      <description>I want to have duplicates into new datasets also...</description>
      <pubDate>Sat, 25 Nov 2017 16:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416144#M280220</guid>
      <dc:creator>ganandlife</dc:creator>
      <dc:date>2017-11-25T16:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort with nodupkey in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416145#M280221</link>
      <description>&lt;P&gt;HAVING in PROC SQL can select duplicates if they are present in the data.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 16:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416145#M280221</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-11-25T16:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort with nodupkey in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416146#M280222</link>
      <description>&lt;P&gt;The proc sort steps will find the first observation that has the maximum value of FLAG within each group defined by PROMO.&lt;/P&gt;
&lt;P&gt;In PROC SQL the best you can do is find ALL observations that have the maximum value of FLAG within each group.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table new1 as
  select *
  from a
  group by promo
  order by promo
  having flag=max(flag)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In ORACLE or other external databases that have newer implementations of SQL syntax you can use ROW_NUMBER to find the first observation. So something like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
connect to oracle ..... ;
create table new1 as
select * from connection to oracle
(select *
 from a
 order by promo
 having 1=row_number() over (partition by promo order by promo, flag desc)
)
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Nov 2017 16:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-with-nodupkey-in-proc-sql/m-p/416146#M280222</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-25T16:41:27Z</dc:date>
    </item>
  </channel>
</rss>

