<?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: RANK OVER Function - Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737332#M229861</link>
    <description>Thank you !</description>
    <pubDate>Tue, 27 Apr 2021 17:10:50 GMT</pubDate>
    <dc:creator>Adir92</dc:creator>
    <dc:date>2021-04-27T17:10:50Z</dc:date>
    <item>
      <title>RANK OVER Function - Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737322#M229854</link>
      <description>&lt;P&gt;Hello to all, hope you are doing well.&lt;BR /&gt;I have a database TEST that has 5 columns. Here is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID_Customer&lt;/TD&gt;&lt;TD&gt;ID_Project&lt;/TD&gt;&lt;TD&gt;ID_Application&lt;/TD&gt;&lt;TD&gt;Nbre_Application&lt;/TD&gt;&lt;TD&gt;Creation_Application&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200200&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;267&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;20JANV2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200200&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;256&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;10JANV2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200200&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;456&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;15JANV2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;400400&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;120&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;10FEB2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;400400&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;101&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;05JANV2020&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each client, I would like to classify his applications, from the oldest to the most recent with the number 1 for the oldest, 2 for the most recent...&lt;/P&gt;&lt;P&gt;Like this :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID_Customer&lt;/TD&gt;&lt;TD&gt;ID_Project&lt;/TD&gt;&lt;TD&gt;ID_Application&lt;/TD&gt;&lt;TD&gt;Nbre_Application&lt;/TD&gt;&lt;TD&gt;Creation_Application&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200200&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;256&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200200&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;456&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200200&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;267&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;400400&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;101&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;400400&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;120&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know there's a proc rank procedure but here how can I use it ? And is there a way with proc sql ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 16:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737322#M229854</guid>
      <dc:creator>Adir92</dc:creator>
      <dc:date>2021-04-27T16:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: RANK OVER Function - Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737329#M229858</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=have out=want;
    by id_customer;
    var creation_application;
    ranks ranked_creation_application;
run;
proc sort data=want;
     by id_customer ranked_creation_application;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or alternatively&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
    by id_customer creation_application;
run;
data want;
    set have;
    by id_customer;
    if first.id_customer then ranked_creation_application=0;
    ranked_creation_application+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Really no need for SQL here.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 16:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737329#M229858</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-27T16:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: RANK OVER Function - Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737330#M229859</link>
      <description>&lt;P&gt;That would not be a "rank" , that would be a sequence number and not ideal for Proc SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question might be what happens if a single ID_customer value has multiple Id_project values and how that gets treated. The example below resets the sequence for each project. If that is not desired use First.id_customer&lt;/P&gt;
&lt;PRE&gt;Proc sort data=test;
   by Id_customer id_project creation_application;
run;

data want;
   set test;
   by id_customer id_project;
   retain sequence;
   if first.id_project then sequence=1;
   else sequence+1;
run;&lt;/PRE&gt;
&lt;P&gt;The BY statement creates boolean (true/false or 1/0) values for each variable that on the statement indicating whether the specific record is the first or last of a value group. These are accessed using the First. (see the dot) and Last. notation preceding the variable name.&lt;/P&gt;
&lt;P&gt;Retain creates a variable whose value is kept across iteration boundaries of a data step so can be used to do sequences. But you need to reset it to a starting value when needed.&lt;/P&gt;
&lt;P&gt;Bad juju results from changing the values of variables like Creation_application from a date to numeric, or was that just an accident in your "want"?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 17:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737330#M229859</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-27T17:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: RANK OVER Function - Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737332#M229861</link>
      <description>Thank you !</description>
      <pubDate>Tue, 27 Apr 2021 17:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737332#M229861</guid>
      <dc:creator>Adir92</dc:creator>
      <dc:date>2021-04-27T17:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: RANK OVER Function - Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737335#M229863</link>
      <description>Yes I see, no It was an accident, its better with a created variable. Thank you so much ! I will read in detail your explanation to understand it well but the important thing is that it works!</description>
      <pubDate>Tue, 27 Apr 2021 17:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RANK-OVER-Function-Proc-SQL/m-p/737335#M229863</guid>
      <dc:creator>Adir92</dc:creator>
      <dc:date>2021-04-27T17:13:45Z</dc:date>
    </item>
  </channel>
</rss>

