<?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: SQL query not works in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426752#M105180</link>
    <description>&lt;PRE&gt;ROW_NUMBER OVER (PARTITION BY 'sex' ORDER BY height DESC) AS Rank_height&lt;/PRE&gt;
&lt;P&gt;Row_number is window function and is part of ansi sql 2003 and is not implement in Proc sql, but is&amp;nbsp; implemented in most of databases. not sure, I guess proc sql follows SQL 99 standard.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To sum it up, all the window functions like row_number and rank over , sum over, count over, are not available in proc sql. Hence you cannot use them in proc sql. please use data step by variable and first. and last. concepts to get equivalent results. To achieve the same in proc sql will be long and tough process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please check below paper which discusses how to implement window functions(available in most of databases) in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings11/019-2011.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings11/019-2011.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jan 2018 02:09:42 GMT</pubDate>
    <dc:creator>kiranv_</dc:creator>
    <dc:date>2018-01-11T02:09:42Z</dc:date>
    <item>
      <title>SQL query not works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426732#M105173</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This query not works:&lt;/P&gt;
&lt;PRE&gt;proc sql; 
Select *,ROW_NUMBER OVER (PARTITION BY 'sex' ORDER BY height DESC) AS Rank_height
From sashelp.class;
quit;&lt;/PRE&gt;
&lt;P&gt;Please advise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 00:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426732#M105173</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2018-01-11T00:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query not works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426738#M105175</link>
      <description>&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&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 {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 00:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426738#M105175</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-11T00:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query not works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426746#M105177</link>
      <description>&lt;P&gt;It's not valid SAS SQL Syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This part in particular:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ROW_NUMBER OVER (PARTITION BY 'sex' ORDER BY height DESC)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That looks like a different flavour of SQL. If you want this type of analysis there are other methods in SAS to accomplish this that are better suited.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The list of SQL statements that are valid are available here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n1oihmdy7om5rmn1aorxui3kxizl.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n1oihmdy7om5rmn1aorxui3kxizl.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10531"&gt;@GeorgeSAS&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This query not works:&lt;/P&gt;
&lt;PRE&gt;proc sql; 
Select *,ROW_NUMBER OVER (PARTITION BY 'sex' ORDER BY height DESC) AS Rank_height
From sashelp.class;
quit;&lt;/PRE&gt;
&lt;P&gt;Please advise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 01:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426746#M105177</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-11T01:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query not works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426752#M105180</link>
      <description>&lt;PRE&gt;ROW_NUMBER OVER (PARTITION BY 'sex' ORDER BY height DESC) AS Rank_height&lt;/PRE&gt;
&lt;P&gt;Row_number is window function and is part of ansi sql 2003 and is not implement in Proc sql, but is&amp;nbsp; implemented in most of databases. not sure, I guess proc sql follows SQL 99 standard.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To sum it up, all the window functions like row_number and rank over , sum over, count over, are not available in proc sql. Hence you cannot use them in proc sql. please use data step by variable and first. and last. concepts to get equivalent results. To achieve the same in proc sql will be long and tough process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please check below paper which discusses how to implement window functions(available in most of databases) in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings11/019-2011.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings11/019-2011.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 02:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426752#M105180</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-01-11T02:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query not works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426758#M105183</link>
      <description>&lt;P&gt;&amp;nbsp;I guess your query would be equivalent to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=have; by sex; run;

proc rank data=have out=want descending;
by sex;
var height;
ranks rank_height;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jan 2018 04:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426758#M105183</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-01-11T04:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query not works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426763#M105187</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;I like your answer very much, but row_number is slightly different than rank.&amp;nbsp; for&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; sex&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt; height&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if heights are same in sex,&amp;nbsp; rank&amp;nbsp;will be same. In case of row_number it assigns the next number for even the same value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 04:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426763#M105187</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-01-11T04:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query not works</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426770#M105188</link>
      <description>&lt;P&gt;Then I guess you would need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=have; by sex descending height; run;

data want;
do rank_height = 1 by 1 until(last.sex);
    set have; by sex;
    output;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jan 2018 05:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-query-not-works/m-p/426770#M105188</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-01-11T05:18:32Z</dc:date>
    </item>
  </channel>
</rss>

