<?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: Increment by 1 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276466#M55386</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input
  empid : $
  effdt : yymmdd10.
  effseq
  action : $
;
format effdt yymmddd10.;
cards;
Emp1 2016-01-01 5 H
Emp1 2016-01-01 7 M
Emp1 2016-01-01 8 R
Emp1 2016-02-02 0 12
Emp1 2016-05-04 3 12
Emp1 2016-05-04 4 13
;
run;

proc sort data=have;
by empid effdt effseq;
run;

data want;
format empid effdt effseq action; * for variable order;
set have (rename=(effseq=oldeffseq));
by effdt;
retain effseq;
if first.effdt
then do;
  if oldeffseq = 5
  then effseq = 5;
  else effseq = 0;
end;
else effseq + 1;
drop oldeffseq;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 10 Jun 2016 11:22:30 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-06-10T11:22:30Z</dc:date>
    <item>
      <title>Increment by 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276464#M55385</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new toSAS. I have the following scenario and would require help to resolve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EMPID EFFDT &amp;nbsp; &amp;nbsp; &amp;nbsp; EFFSEQ &amp;nbsp; &amp;nbsp;ACTION&lt;BR /&gt;Emp1 2016-01-01 &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; H&lt;BR /&gt;Emp1 2016-01-01 &amp;nbsp; &amp;nbsp; 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;BR /&gt;Emp1 2016-01-01 &amp;nbsp; &amp;nbsp; 8 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; R&lt;BR /&gt;Emp1 2016-02-02 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&lt;BR /&gt;Emp1 2016-05-04 &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&lt;BR /&gt;Emp1 2016-05-04 &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If an Employee has a EFFSEQ starting with 5 in the input file for a particular EFFDT, then his EFFSEQ should increment like 5,6,7...&lt;/P&gt;&lt;P&gt;If an Employee has a EFFSEQ starting other than 5 in the input file for a particular EFFDT, then his EFFSEQ should increment like 0,1,2..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here in this case, I would expect the below output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EMPID EFFDT &amp;nbsp; &amp;nbsp; &amp;nbsp;EFFSEQ ACTION&lt;BR /&gt;Emp1 2016-01-01 &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;H&lt;BR /&gt;Emp1 2016-01-01 &amp;nbsp; &amp;nbsp;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;BR /&gt;Emp1 2016-01-01 &amp;nbsp; &amp;nbsp;7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;R&lt;BR /&gt;Emp1 2016-02-02 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&lt;BR /&gt;Emp1 2016-05-04 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&lt;BR /&gt;Emp1 2016-05-04 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 11:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276464#M55385</guid>
      <dc:creator>Saranya</dc:creator>
      <dc:date>2016-06-10T11:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: Increment by 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276466#M55386</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input
  empid : $
  effdt : yymmdd10.
  effseq
  action : $
;
format effdt yymmddd10.;
cards;
Emp1 2016-01-01 5 H
Emp1 2016-01-01 7 M
Emp1 2016-01-01 8 R
Emp1 2016-02-02 0 12
Emp1 2016-05-04 3 12
Emp1 2016-05-04 4 13
;
run;

proc sort data=have;
by empid effdt effseq;
run;

data want;
format empid effdt effseq action; * for variable order;
set have (rename=(effseq=oldeffseq));
by effdt;
retain effseq;
if first.effdt
then do;
  if oldeffseq = 5
  then effseq = 5;
  else effseq = 0;
end;
else effseq + 1;
drop oldeffseq;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jun 2016 11:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276466#M55386</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-10T11:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Increment by 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276467#M55387</link>
      <description>&lt;P&gt;Hi Saranya,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your problem could be solved with a proper sorting and using first. statment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first think that you need to do is sort data&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
  by EMPID EFFDT EFFSEQ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After that, you data will be sorted. Now you are able to use the statement FIRST.&amp;nbsp;in a data step, that identificate the first element in a group. In that case you want to identify first EFFDT. Depending on if it is the first EFFDT or not, you must operate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do something like&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
  Set have;
  By EMPID EFFDT EFFSEQ;

  retain count;

  if first.EFFDT and EFFSEQ=5 then EFFSEQ=count;
  else if first.EFFDT and EFFSEQ ne 5 then count=0;
  else if not first.EFFDT  then count=count+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is going to&amp;nbsp;generate the variable that you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 11:23:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276467#M55387</guid>
      <dc:creator>arodriguez</dc:creator>
      <dc:date>2016-06-10T11:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: Increment by 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276658#M55458</link>
      <description>&lt;PRE&gt;
There are too many scenarios you need to consider about.


&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jun 2016 07:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276658#M55458</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-13T07:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Increment by 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276849#M55511</link>
      <description>&lt;P&gt;Hi KurtBremser/Arodriguez/Ksharp,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks All for your replies &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;KurtBremser's solution seemed to work. Anyways i'm checking the other solutions too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Saranya&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 06:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increment-by-1/m-p/276849#M55511</guid>
      <dc:creator>Saranya</dc:creator>
      <dc:date>2016-06-13T06:20:27Z</dc:date>
    </item>
  </channel>
</rss>

