<?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: sas sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sas-sql/m-p/766489#M242922</link>
    <description>&lt;P&gt;ROW_NUMBER() isn't valid in SAS SQL, I think that's MS SQL?&lt;/P&gt;
&lt;P&gt;All DBs do this one a bit differently, Oracle is ROWNUM for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried using the MONOTONIC() function or using the OBS= data set option?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you were also missing a comma in the ORDER BY clause.&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(obs=2) as
     select * 
	 from test_sql
	   order by cusip, date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;

     select * , monotonic() as rowNum
	 from test_sql
         where calculated rowNum &amp;lt;=2
	   order by cusip, date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360730"&gt;@georgel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to keep the first two observations ordered by date by group using sql in one step&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     select *, ROW_NUMBER()
	 from test_sql
	 where ROW_NUMBER&amp;lt;=2
	   order by cusip date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above does not work&lt;/P&gt;
&lt;P&gt;Many thanks in advance&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Sep 2021 22:06:30 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-09-07T22:06:30Z</dc:date>
    <item>
      <title>sas sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-sql/m-p/766484#M242921</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to keep the first two observations ordered by date by group using sql in one step&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     select *, ROW_NUMBER()
	 from test_sql
	 where ROW_NUMBER&amp;lt;=2
	   order by cusip date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above does not work&lt;/P&gt;
&lt;P&gt;Many thanks in advance&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 21:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-sql/m-p/766484#M242921</guid>
      <dc:creator>georgel</dc:creator>
      <dc:date>2021-09-07T21:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: sas sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-sql/m-p/766489#M242922</link>
      <description>&lt;P&gt;ROW_NUMBER() isn't valid in SAS SQL, I think that's MS SQL?&lt;/P&gt;
&lt;P&gt;All DBs do this one a bit differently, Oracle is ROWNUM for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried using the MONOTONIC() function or using the OBS= data set option?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you were also missing a comma in the ORDER BY clause.&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(obs=2) as
     select * 
	 from test_sql
	   order by cusip, date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;

     select * , monotonic() as rowNum
	 from test_sql
         where calculated rowNum &amp;lt;=2
	   order by cusip, date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360730"&gt;@georgel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to keep the first two observations ordered by date by group using sql in one step&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
     select *, ROW_NUMBER()
	 from test_sql
	 where ROW_NUMBER&amp;lt;=2
	   order by cusip date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above does not work&lt;/P&gt;
&lt;P&gt;Many thanks in advance&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 22:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-sql/m-p/766489#M242922</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-07T22:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: sas sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-sql/m-p/766497#M242929</link>
      <description>&lt;P&gt;Note that SQL does not guarantee that rows will be processed in the table order.&lt;/P&gt;
&lt;P&gt;If you read a single table and use option &lt;FONT face="courier new,courier"&gt;proc sql nothreads&lt;/FONT&gt;,&amp;nbsp; it should still happen though.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Sep 2021 23:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-sql/m-p/766497#M242929</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-09-07T23:03:28Z</dc:date>
    </item>
  </channel>
</rss>

