<?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 Get count  of rows in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/446950#M69486</link>
    <description>I have a data step thst gives me count&lt;BR /&gt;Of row per my grouping&lt;BR /&gt;&lt;BR /&gt;Here it is&lt;BR /&gt;Data dep5;&lt;BR /&gt;Set dep5;&lt;BR /&gt;Count +1;&lt;BR /&gt;By top;&lt;BR /&gt;If first.top then count =1;&lt;BR /&gt;Run;&lt;BR /&gt;It works but it starts with the earliest date as 1 and most current with 5 I would need it to be the opposite of that for example&lt;BR /&gt;&lt;BR /&gt;Top. Date. Count. Need to look&lt;BR /&gt;1. 02/01/2018. 1. 3&lt;BR /&gt;2. 02/05/2018. 2. 2&lt;BR /&gt;3. 03/01/2018. 3. 1</description>
    <pubDate>Mon, 19 Mar 2018 22:08:16 GMT</pubDate>
    <dc:creator>Gil_</dc:creator>
    <dc:date>2018-03-19T22:08:16Z</dc:date>
    <item>
      <title>Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/446950#M69486</link>
      <description>I have a data step thst gives me count&lt;BR /&gt;Of row per my grouping&lt;BR /&gt;&lt;BR /&gt;Here it is&lt;BR /&gt;Data dep5;&lt;BR /&gt;Set dep5;&lt;BR /&gt;Count +1;&lt;BR /&gt;By top;&lt;BR /&gt;If first.top then count =1;&lt;BR /&gt;Run;&lt;BR /&gt;It works but it starts with the earliest date as 1 and most current with 5 I would need it to be the opposite of that for example&lt;BR /&gt;&lt;BR /&gt;Top. Date. Count. Need to look&lt;BR /&gt;1. 02/01/2018. 1. 3&lt;BR /&gt;2. 02/05/2018. 2. 2&lt;BR /&gt;3. 03/01/2018. 3. 1</description>
      <pubDate>Mon, 19 Mar 2018 22:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/446950#M69486</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2018-03-19T22:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/446967#M69490</link>
      <description>&lt;P&gt;please try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have ;
input Top Date: mmddyy10.  ;
format date date9.;
cards;
1 02/01/2018 
2 02/05/2018 
3 03/01/2018 
;

proc sort data=have ;
by descending date;
run;

data want;
set have;
by descending date ;
retain count;
if first.date then count+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 23:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/446967#M69490</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-03-19T23:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/446969#M69492</link>
      <description>&lt;P&gt;First you sort your data by descending and count the records by id and then sort back to ascending.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;                                                                                                                              
format date date9.;                                                                                                                     
infile datalines dlm=" ";                                                                                                               
input ID $ Date date9. ;                                                                                                                
datalines;                                                                                                                              
A 01MAR2018                                                                                                                             
A 02MAR2018                                                                                                                             
A 03MAR2018                                                                                                                             
B 01MAR2018                                                                                                                             
B 02MAR2018                                                                                                                             
B 03MAR2018                                                                                                                             
;                                                                                                                                       
run;                                                                                                                                    
                                                                                                                                        
proc sort data=have;                                                                                                                    
by id descending date;                                                                                                                  
run;                                                                                                                                    
                                                                                                                                        
data want;                                                                                                                              
set have;                                                                                                                               
by id;                                                                                                                                  
if first.id then count=1;                                                                                                               
else count+1;                                                                                                                           
run;                                                                                                                                    
proc sort data=want;                                                                                                                    
by id date;                                                                                                                             
proc print data=want;                                                                                                                   
run; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Mar 2018 23:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/446969#M69492</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-19T23:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447069#M69500</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
input Top Date: mmddyy10.  ;
format date date9.;
cards;
1 02/01/2018 
2 02/05/2018 
3 03/01/2018 
;
data want;
 set have nobs=nobs;
 want=nobs+1-_n_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Mar 2018 12:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447069#M69500</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-03-20T12:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447106#M69504</link>
      <description>Thanks for response SuryaKiran&amp;nbsp;&lt;BR /&gt;I'm still getting the number sequence from the earliest being one and latest with 20 since that number can fluctuate&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Mar 2018 14:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447106#M69504</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2018-03-20T14:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447110#M69506</link>
      <description>Hi Kshatp,&lt;BR /&gt;I use your code an the output was&lt;BR /&gt;Dep5. Date. Id&lt;BR /&gt;146070, 03/18/18. 1536&lt;BR /&gt;146069, 03/28/18. 2334</description>
      <pubDate>Tue, 20 Mar 2018 14:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447110#M69506</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2018-03-20T14:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447140#M69508</link>
      <description>&lt;BR /&gt;Jagadishkatam&amp;nbsp;,&lt;BR /&gt;I tried your script I need to incorporate Id for grouping&lt;BR /&gt;&lt;BR /&gt;Id Date. Count. Need to look&lt;BR /&gt;1. 02/01/2018. 1. 3&lt;BR /&gt;2. 02/05/2018. 1. 3&lt;BR /&gt;3. 03/01/2018. 1. 3&lt;BR /&gt;1. 02/03/2018. 2. 2&lt;BR /&gt;2. 02/07/2018. 2. 2&lt;BR /&gt;3. 03/04/2018. . 2. 2&lt;BR /&gt;1. 02/04/2018b. . 3. 1&lt;BR /&gt;2. 02/08/2018. 3. 1&lt;BR /&gt;3. 03/09/2018. 3. 1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Mar 2018 14:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447140#M69508</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2018-03-20T14:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447245#M69515</link>
      <description>Hi Ksharp&lt;BR /&gt;I got it to work with your example ..How can refer dep5 instead datalines?</description>
      <pubDate>Tue, 20 Mar 2018 19:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447245#M69515</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2018-03-20T19:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447252#M69516</link>
      <description>&lt;P&gt;Proper sort order will solve your problem. Please provide with some actual sample data with few records.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 19:49:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447252#M69516</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-20T19:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447264#M69517</link>
      <description>SuryaKiran&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;How do I refer table dep5 it's in lib work in your code ?</description>
      <pubDate>Tue, 20 Mar 2018 20:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447264#M69517</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2018-03-20T20:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447387#M69519</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set dep5 nobs=nobs;
 want=nobs+1-_n_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Mar 2018 12:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447387#M69519</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-03-21T12:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447530#M69534</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=dep5;                                                                                                                    
by top descending date;                                                                                                                  
run;                                                                                                                                    
                                                                                                                                        
data dep5;                                                                                                                              
set dep5;                                                                                                                               
by top;                                                                                                                                  
if first.top then count=1;                                                                                                               
else count+1;                                                                                                                           
run;                                                                                                                                    
proc sort data=dep5;                                                                                                                    
by top date;                                                                                                                             
proc print data=dep5;                                                                                                                   
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Mar 2018 18:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447530#M69534</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-21T18:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447814#M69560</link>
      <description>Thank for assistance the data is still giving me count from latest date to one and current date with higher number&lt;BR /&gt;&lt;BR /&gt;Here is example of what I need&lt;BR /&gt;Id. Date. Count&lt;BR /&gt;Was. 01/03/2018. 5&lt;BR /&gt;Was. 01/04/2018. 4&lt;BR /&gt;Was. 01/05/2018. 3&lt;BR /&gt;Was. 01/06/2018. 2&lt;BR /&gt;Was. 01/07/2018. 1&lt;BR /&gt;Abc 01/03/2018. 5&lt;BR /&gt;Abc 01/04/2018. 4&lt;BR /&gt;Abc 01/05/2018. 3&lt;BR /&gt;Abc 01/03/2018. 2&lt;BR /&gt;Abc 01/02/2018. 1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;When I use code you provided it does the opposite. Thank you for assistance</description>
      <pubDate>Thu, 22 Mar 2018 15:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/447814#M69560</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2018-03-22T15:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Get count  of rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/448407#M69593</link>
      <description>&lt;P&gt;could you please try this code, it is the same I provided earlier&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;not sure if you tried earlier but if you could try it will help you&amp;nbsp;&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 descending date;
run;

data want;
set have;
by descending date ;
retain count;
if first.date then count+1;
run;

proc sort data=want;
by id date;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Mar 2018 08:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Get-count-of-rows/m-p/448407#M69593</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-03-24T08:51:19Z</dc:date>
    </item>
  </channel>
</rss>

