<?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: Numbering rows based on defined criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847621#M335115</link>
    <description>&lt;P&gt;It works&lt;/P&gt;
&lt;P&gt;Please see the code below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.EXAMPLE_0000;
    LENGTH
        PRD_YR             8
        GVKEY            $ 6 ;
    FORMAT
        PRD_YR           BEST12.
        GVKEY            $CHAR6. ;
    INFORMAT
        PRD_YR           BEST12.
        GVKEY            $CHAR6. ;
    INFILE DATALINES4
        DLM='7F'x
        MISSOVER
        DSD ;
    INPUT
        PRD_YR           : BEST32.
        GVKEY            : $CHAR6. ;
DATALINES4;
1999&amp;#127;001034
2001&amp;#127;001034
2002&amp;#127;001034
2003&amp;#127;001034
2004&amp;#127;001034
2006&amp;#127;001034
2007&amp;#127;001034
2018&amp;#127;001045
2019&amp;#127;001045
2020&amp;#127;001045
2014&amp;#127;001050
2020&amp;#127;001076
2002&amp;#127;001078
2003&amp;#127;001078
2004&amp;#127;001078
2005&amp;#127;001078
2006&amp;#127;001078
2007&amp;#127;001078
2008&amp;#127;001078
2009&amp;#127;001078
2010&amp;#127;001078
2011&amp;#127;001078
2012&amp;#127;001078
2013&amp;#127;001078
2014&amp;#127;001078
2015&amp;#127;001078
2016&amp;#127;001078
2017&amp;#127;001078
2018&amp;#127;001078
2019&amp;#127;001078
2021&amp;#127;001078
;;;;
proc sort data=EXAMPLE_0000;
by GVKEY;
run;
data EXAMPLE_0001;
Retain year_of_series GVKEY PRD_YR;
set EXAMPLE_0000;
by GVKEY;
if first.GVKEY then  year_of_series=0;
year_of_series+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 04 Dec 2022 01:24:08 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2022-12-04T01:24:08Z</dc:date>
    <item>
      <title>Numbering rows based on defined criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847595#M335104</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have the following data set:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* --------------------------------------------------------------------
   Code generated by a SAS task
   
   Generated on Saturday, December 3, 2022 at 10:48:36 PM
   By task:     Import Data Wizard
   
   Source file: C:\Users\Lior\Downloads\example.xlsx
   Server:      Local File System
   
   Output data: WORK.EXAMPLE_0000
   Server:      Local
   -------------------------------------------------------------------- */

/* --------------------------------------------------------------------
   This DATA step reads the data values from DATALINES within the SAS
   code. The values within the DATALINES were extracted from the Excel
   source file by the Import Data wizard.
   -------------------------------------------------------------------- */

DATA WORK.EXAMPLE_0000;
    LENGTH
        PRD_YR             8
        GVKEY            $ 6 ;
    FORMAT
        PRD_YR           BEST12.
        GVKEY            $CHAR6. ;
    INFORMAT
        PRD_YR           BEST12.
        GVKEY            $CHAR6. ;
    INFILE DATALINES4
        DLM='7F'x
        MISSOVER
        DSD ;
    INPUT
        PRD_YR           : BEST32.
        GVKEY            : $CHAR6. ;
DATALINES4;
1999&amp;#127;001034
2001&amp;#127;001034
2002&amp;#127;001034
2003&amp;#127;001034
2004&amp;#127;001034
2006&amp;#127;001034
2007&amp;#127;001034
2018&amp;#127;001045
2019&amp;#127;001045
2020&amp;#127;001045
2014&amp;#127;001050
2020&amp;#127;001076
2002&amp;#127;001078
2003&amp;#127;001078
2004&amp;#127;001078
2005&amp;#127;001078
2006&amp;#127;001078
2007&amp;#127;001078
2008&amp;#127;001078
2009&amp;#127;001078
2010&amp;#127;001078
2011&amp;#127;001078
2012&amp;#127;001078
2013&amp;#127;001078
2014&amp;#127;001078
2015&amp;#127;001078
2016&amp;#127;001078
2017&amp;#127;001078
2018&amp;#127;001078
2019&amp;#127;001078
2021&amp;#127;001078
;;;;



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I wrote the following code in the order number of each row belonging to a certain firm. meaning when the firm switches to a new firm, the numbering should start again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; if first.GVKEY then year_of_series=0;
 year_of_series+1;
&lt;/PRE&gt;
&lt;P&gt;But when I run this code I just receive a file that numbers all the rows in the file as one series.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know why the code is not working?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Lior&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2022 21:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847595#M335104</guid>
      <dc:creator>lioradam</dc:creator>
      <dc:date>2022-12-03T21:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Numbering rows based on defined criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847608#M335107</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133482"&gt;@lioradam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... and I wrote the following code in the order number of each row belonging to a certain firm. meaning when the firm switches to a new firm, the numbering should start again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; if first.GVKEY then year_of_series=0;
 year_of_series+1;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please don't ever show us a partial data step. This code can't be evaluated unless you show us the ENTIRE data step where it is used. I have a guess why you are getting the wrong results, but I shouldn't have to guess.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2022 22:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847608#M335107</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-03T22:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Numbering rows based on defined criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847612#M335110</link>
      <description>Your clue would appear in the log.  (You must read the log every time!)  There should be a message telling you that first.GVKEY is unitialized.  That means it was never assigned a value, which means your DATA step is missing a BY statement.  &lt;BR /&gt;&lt;BR /&gt;After the SET statement add:&lt;BR /&gt;&lt;BR /&gt;by gvkey;&lt;BR /&gt;&lt;BR /&gt;That's what creates first.gvkey and last.gvkey.</description>
      <pubDate>Sat, 03 Dec 2022 22:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847612#M335110</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-12-03T22:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Numbering rows based on defined criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847621#M335115</link>
      <description>&lt;P&gt;It works&lt;/P&gt;
&lt;P&gt;Please see the code below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.EXAMPLE_0000;
    LENGTH
        PRD_YR             8
        GVKEY            $ 6 ;
    FORMAT
        PRD_YR           BEST12.
        GVKEY            $CHAR6. ;
    INFORMAT
        PRD_YR           BEST12.
        GVKEY            $CHAR6. ;
    INFILE DATALINES4
        DLM='7F'x
        MISSOVER
        DSD ;
    INPUT
        PRD_YR           : BEST32.
        GVKEY            : $CHAR6. ;
DATALINES4;
1999&amp;#127;001034
2001&amp;#127;001034
2002&amp;#127;001034
2003&amp;#127;001034
2004&amp;#127;001034
2006&amp;#127;001034
2007&amp;#127;001034
2018&amp;#127;001045
2019&amp;#127;001045
2020&amp;#127;001045
2014&amp;#127;001050
2020&amp;#127;001076
2002&amp;#127;001078
2003&amp;#127;001078
2004&amp;#127;001078
2005&amp;#127;001078
2006&amp;#127;001078
2007&amp;#127;001078
2008&amp;#127;001078
2009&amp;#127;001078
2010&amp;#127;001078
2011&amp;#127;001078
2012&amp;#127;001078
2013&amp;#127;001078
2014&amp;#127;001078
2015&amp;#127;001078
2016&amp;#127;001078
2017&amp;#127;001078
2018&amp;#127;001078
2019&amp;#127;001078
2021&amp;#127;001078
;;;;
proc sort data=EXAMPLE_0000;
by GVKEY;
run;
data EXAMPLE_0001;
Retain year_of_series GVKEY PRD_YR;
set EXAMPLE_0000;
by GVKEY;
if first.GVKEY then  year_of_series=0;
year_of_series+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Dec 2022 01:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847621#M335115</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-12-04T01:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: Numbering rows based on defined criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847622#M335116</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The "BY statement" indeed was written incorrectly.&lt;/P&gt;
&lt;P&gt;Thanks a lot!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lior&lt;/P&gt;</description>
      <pubDate>Sun, 04 Dec 2022 01:40:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847622#M335116</guid>
      <dc:creator>lioradam</dc:creator>
      <dc:date>2022-12-04T01:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: Numbering rows based on defined criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847623#M335117</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 04 Dec 2022 01:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbering-rows-based-on-defined-criteria/m-p/847623#M335117</guid>
      <dc:creator>lioradam</dc:creator>
      <dc:date>2022-12-04T01:40:47Z</dc:date>
    </item>
  </channel>
</rss>

