<?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: problems in the &amp;quot;over&amp;quot; statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/problems-in-the-quot-over-quot-statement/m-p/869614#M343485</link>
    <description>&lt;P&gt;Please post code or log examples in a text box opened on the forum using the &amp;lt;/&amp;gt; icon above the message box. That will separate out code from question or problem descriptions and make it easier to follow. Also code pasted into a text box will retain formatting, such as code indentation, or diagnostic characters correctly if posting SAS log text as the main message windows will reformat pasted text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your SQL uses several items that are not available in SAS besides "over" : "Rank()" and "partition".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SAS procedure SORT will remove duplicate observations.&lt;/P&gt;
&lt;P&gt;Here is a brief example creating a small data set and then sort code to create wanted data without duplicate records.&lt;/P&gt;
&lt;PRE&gt;data example;
  input x y z;
datalines;
1  2  3
2  3  4
1  2  3
2  3  5
3  4  5
1  2  3
;

proc sort data=example out=want nodup;
  by x;
run;&lt;/PRE&gt;
&lt;P&gt;Note that the duplicate rows for 1 2 3 are removed.&lt;/P&gt;
&lt;P&gt;The data step as shown to create the example data set is the way to provide an example of your data if needed. If this basic sort does not do what you want then provide an example starting data set and the desired result made from the example describing any rules.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2023 16:17:54 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-04-13T16:17:54Z</dc:date>
    <item>
      <title>problems in the "over" statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problems-in-the-quot-over-quot-statement/m-p/869610#M343483</link>
      <description>&lt;P&gt;The following code runs perfectly in aginity/netezza sql, but does not work in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql: 
Create table new_table as 
select * from (select * from( select a.* from (select *, rank () over (partition by var_a order by var_id) as rank1 from old_table) a where a.rank1=1) a) b&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I try to run this code in proc sql, it won't let me do this because of problems in the "over" statement. This code is used for removing duplicates : for groups of duplicate records within the data, it leaves only one record. Is there a way to modify this sql code so that in runs in proc sql? Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 16:19:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problems-in-the-quot-over-quot-statement/m-p/869610#M343483</guid>
      <dc:creator>ganatbasa</dc:creator>
      <dc:date>2023-04-13T16:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: problems in the "over" statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problems-in-the-quot-over-quot-statement/m-p/869612#M343484</link>
      <description>&lt;P&gt;That is not valid ANSI 92 SQL syntax so it cannot work in PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to take only the first observation in a BY group use a DATA step instead of trying to trick the set logic of SQL to handle observation order.&lt;/P&gt;
&lt;P&gt;So if you have a dataset that is sorted by GROUP and DATE you can use a step like this to find the earliest observation for each group.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
  by group date;
run;
data first_per_group;
  set have;
  by group date ;
  if first.group;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Looks like your SQL is using var_a as the GROUP variable and var_id as the sub-ordering variable within the groups, like the DATE variable in my example data step.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 19:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problems-in-the-quot-over-quot-statement/m-p/869612#M343484</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-13T19:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: problems in the "over" statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problems-in-the-quot-over-quot-statement/m-p/869614#M343485</link>
      <description>&lt;P&gt;Please post code or log examples in a text box opened on the forum using the &amp;lt;/&amp;gt; icon above the message box. That will separate out code from question or problem descriptions and make it easier to follow. Also code pasted into a text box will retain formatting, such as code indentation, or diagnostic characters correctly if posting SAS log text as the main message windows will reformat pasted text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your SQL uses several items that are not available in SAS besides "over" : "Rank()" and "partition".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SAS procedure SORT will remove duplicate observations.&lt;/P&gt;
&lt;P&gt;Here is a brief example creating a small data set and then sort code to create wanted data without duplicate records.&lt;/P&gt;
&lt;PRE&gt;data example;
  input x y z;
datalines;
1  2  3
2  3  4
1  2  3
2  3  5
3  4  5
1  2  3
;

proc sort data=example out=want nodup;
  by x;
run;&lt;/PRE&gt;
&lt;P&gt;Note that the duplicate rows for 1 2 3 are removed.&lt;/P&gt;
&lt;P&gt;The data step as shown to create the example data set is the way to provide an example of your data if needed. If this basic sort does not do what you want then provide an example starting data set and the desired result made from the example describing any rules.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 16:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problems-in-the-quot-over-quot-statement/m-p/869614#M343485</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-13T16:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: problems in the "over" statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problems-in-the-quot-over-quot-statement/m-p/869648#M343508</link>
      <description>&lt;P&gt;If you simply must have an SQL solution use DISTINCT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using BallardW's data statement&amp;nbsp;you can do&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select
distinct a.*
from
example a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to get&lt;/P&gt;
&lt;DIV&gt;&lt;BR /&gt;
&lt;TABLE class="table" width="120px" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;COL class="data" /&gt; &lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="colgroup" width="40px"&gt;x&lt;/TH&gt;
&lt;TH class="header" scope="colgroup" width="40px"&gt;y&lt;/TH&gt;
&lt;TH class="header" scope="colgroup" width="40px"&gt;z&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="40px" class="b data"&gt;1&lt;/TD&gt;
&lt;TD width="40px" class="b data"&gt;2&lt;/TD&gt;
&lt;TD width="40px" class="b data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" class="b data"&gt;2&lt;/TD&gt;
&lt;TD width="40px" class="b data"&gt;3&lt;/TD&gt;
&lt;TD width="40px" class="b data"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" class="b data"&gt;2&lt;/TD&gt;
&lt;TD width="40px" class="b data"&gt;3&lt;/TD&gt;
&lt;TD width="40px" class="b data"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 19:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problems-in-the-quot-over-quot-statement/m-p/869648#M343508</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2023-04-13T19:06:21Z</dc:date>
    </item>
  </channel>
</rss>

