<?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: First dot and last dot conversion into proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714986#M220799</link>
    <description>&lt;P&gt;There is no such thing.&amp;nbsp; SQL does not guarantee the order in which it selects observation, so the "last" observation is unreliable.&amp;nbsp; It could change from run to run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is an unsupported, unguaranteed "monotonic" feature of SQL if you want to go that route.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jan 2021 13:46:25 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2021-01-28T13:46:25Z</dc:date>
    <item>
      <title>First dot and last dot conversion into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714980#M220795</link>
      <description>&lt;P&gt;Hi Everyone, Can anybody help me with the below issue?&lt;/P&gt;&lt;P&gt;-&amp;gt; wanted to convert the following datastep (containing first. last. functionality) into Proc sql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data readin;
input ID Name $ Score;
cards;
1     David   45
1     David   74
2     Sam     45
2     Ram     54
3     Bane    87
3     Mary    92
3     Bane    87
4     Dane    23
5     Jenny   87
5     Ken     87
6     Simran  63
8     Priya   72
;
run;
&lt;BR /&gt;proc sort data=readin;&lt;BR /&gt;by ID Name;&lt;BR /&gt;run;

data b;
set readin;
by ID Name;
if last.ID or last.Name then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jan 2021 13:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714980#M220795</guid>
      <dc:creator>karrora1201</dc:creator>
      <dc:date>2021-01-28T13:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: First dot and last dot conversion into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714984#M220797</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data readin;
input ID Name $ Score;
cards;
1     David   45
1     David   74
2     Sam     45
2     Ram     54
3     Bane    87
3     Mary    92
3     Bane    87
4     Dane    23
5     Jenny   87
5     Ken     87
6     Simran  63
8     Priya   72
;
run;

proc sql;
create table want as
select distinct *
 from (select monotonic() as _n_,* from readin)
  group by id,name
   having _n_=max(_n_);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jan 2021 13:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714984#M220797</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-01-28T13:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: First dot and last dot conversion into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714985#M220798</link>
      <description>&lt;P&gt;The only problem using the MONOTONIC() function in PROC SQL is that it is unsupported. It works today, it may not work in the next release (or some future release) of SAS. And so, if you are writing code with an unsupported feature, this can lead to problems and the original problem is probably best left as a DATA step.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 13:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714985#M220798</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-28T13:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: First dot and last dot conversion into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714986#M220799</link>
      <description>&lt;P&gt;There is no such thing.&amp;nbsp; SQL does not guarantee the order in which it selects observation, so the "last" observation is unreliable.&amp;nbsp; It could change from run to run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is an unsupported, unguaranteed "monotonic" feature of SQL if you want to go that route.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 13:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714986#M220799</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-01-28T13:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: First dot and last dot conversion into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714990#M220801</link>
      <description>&lt;P&gt;Maxim 14: Use the Right Tool, which is the data step for such tasks. SQL code would be much more complicated, harder to maintain, and have worse performance. SQL does not have the concept of sequence that the data step has, and so that must be forced, usually with a sub-select which has very bad performance, or an intermediate step that creates a sequence number through use of the undocumented (and therefore not advisable) MONOTONIC() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW last.ID implies last.Name, so it is sufficient to check for last.Name in your example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A possible SQL code might be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    id,
    name,
    score
  from (
    select *, monotonic() as seq
    from readin
  )
  group by id, name
  having seq = max(seq)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but that is NOT guaranteed to create the same result as the SORT/DATA steps.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 13:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714990#M220801</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-28T13:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: First dot and last dot conversion into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714993#M220804</link>
      <description>&lt;P&gt;I agree to both&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;for their professional neat advice. Genius &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;'s solution is something that came to my mind too. However, this certainly&amp;nbsp; is a not a question that's production code related and a fun question perhaps?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The subject matter though that's worth learning is whether or not there is a clean way of reading a dataset in a sequential order. Once we have this, a possible conditional construct utility may surface. I'm afraid Proc SQL doesn't quite have the row order functionality and in SQL of any variant requires explicit determination of a row order unlike the datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The author of t&lt;/SPAN&gt;&lt;SPAN&gt;he best-selling SQL book of all time&amp;nbsp;Ben Forta writes, "&lt;EM&gt;the retrieved data&amp;nbsp; from underlying tables&amp;nbsp; is not displayed in a mere random order. If unsorted, data will typically be displayed in the order in which it appears in the underlying tables. This could be the order in which the data was added to the tables initially. However, if data was subsequently updated or deleted, the order will be affected by how the DBMS reuses reclaimed storage space. The end result is that you cannot (and should not) rely on the sort order if you do not explicitly control it. Relational database&amp;nbsp;design theory states that the sequence of retrieved data cannot be assumed to have significance if ordering was not explicitly specified"&lt;/EM&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note: Some even go as far to believe almighty perhaps created EF Codd to relate and normalise tables and then Ben forta to play with it. If Ben wrote it, I believe him.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 14:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-dot-and-last-dot-conversion-into-proc-sql/m-p/714993#M220804</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-28T14:05:54Z</dc:date>
    </item>
  </channel>
</rss>

