<?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: Counter variable with filters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435425#M282029</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input year department $ position $ emp_id $;
datalines;
506 sales assist ls3891g 
607 sales assist ls3891g 
708 sales assist ls3891g 
910 sales assist ls3891g 
1011 sales assist ls3891g 
1112 sales assist ls3891g 
1213 sales assist ls3891g 
1314 sales assist ls3891g 
1415 sales assist ls3891g 
1516 sales assist ls3891g 
1617 sales assist ls3891g 
1718 sales assist ls3891g 
;
run;

data makegroup;
set test;
by year department position emp_id;
if first.emp_id then countvar=1;
countvar +1;
run;

proc sql;
create table counts2 as 
select department, position, emp_id, count(countvar) as totalyears from makegroup
group by department, position, emp_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;department&lt;/TD&gt;&lt;TD&gt;position&lt;/TD&gt;&lt;TD&gt;emp_id&lt;/TD&gt;&lt;TD&gt;totalyears&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would expect it to look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;department&lt;/TD&gt;&lt;TD&gt;position&lt;/TD&gt;&lt;TD&gt;emp_id&lt;/TD&gt;&lt;TD&gt;totalyears&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Thu, 08 Feb 2018 20:43:09 GMT</pubDate>
    <dc:creator>serrld113</dc:creator>
    <dc:date>2018-02-08T20:43:09Z</dc:date>
    <item>
      <title>Counter variable with filters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435389#M282022</link>
      <description>&lt;P&gt;Hey guys, I'm struggling with building a counter variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have to do is count the number of years an employee has been in a certain position in a certain department, without counting the employees who were in that position previously. I only need continuous years of employment, if there is a break in employment, then I would only want to count from the most recent hire year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My variables are: year, department, position, emp_id,. After running a proc sql to pull the employees I ran a proc sort and then this data step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data makegroup;
set match;
countvar +1;
by year department position emp_id;
if first.year then countvar=1;
run;&lt;/PRE&gt;&lt;P&gt;This unfortunately starts a counter from 1 all the way to 40k+ ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next step I have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table want as 
select year, department, position, emp_id,
		count(countvar) as total_years
from makegroup
group by year, department, position, emp_id
having year = max(year)
order by year, department, position, emp_id
;
quit;&lt;/PRE&gt;&lt;P&gt;Which is great except it gives me the employees that were previously in that position and it doesn't account for breaks in employment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be much appreciated! Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in this table there is a break between 0708 and 0910, so I want to count 9 years, instead my code counts for 12.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;year&lt;/TD&gt;&lt;TD&gt;department&lt;/TD&gt;&lt;TD&gt;position&lt;/TD&gt;&lt;TD&gt;emp_id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;506&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;607&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;708&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;910&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1011&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1112&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1213&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1314&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1415&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1516&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1617&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1718&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 19:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435389#M282022</guid>
      <dc:creator>serrld113</dc:creator>
      <dc:date>2018-02-08T19:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: Counter variable with filters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435394#M282023</link>
      <description>&lt;PRE&gt;count( distinct countvar)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to count the distinct occurrences?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 19:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435394#M282023</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-08T19:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Counter variable with filters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435395#M282024</link>
      <description>You could easily do something like left join select distinct on position and emp_id where position = "one to get rid of". Then on the join do on a.emp_id != b.emp_id. To remove the employee IDs that already had the position. You would have to recount after removing the employees, if you do not want to recount instead of removing make a flag and then in if first. statement say if first.year and flag=1 then countvar=1;. Hard for me to do without coding the whole thing but this should give you some ideas.</description>
      <pubDate>Thu, 08 Feb 2018 19:32:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435395#M282024</guid>
      <dc:creator>Larrihoover</dc:creator>
      <dc:date>2018-02-08T19:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: Counter variable with filters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435398#M282025</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi ladies,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need a counter for each employee, so it's first.empid not first.year&lt;/P&gt;
&lt;P&gt;It's possible you may need to modify your BY order as well, but you can play around with that and see what you need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case if they switch department/position the counter will reset, if you don't want that remove those from the BY statement or put them after the emp_id in the BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data makegroup;
set match;

by year department position emp_id;

if first.emp_id r then countvar=1;

countvar +1;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS. Please only ask one question at a time, it helps you to get answers faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/157069"&gt;@serrld113&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hey &lt;STRIKE&gt;guys&lt;/STRIKE&gt;, I'm struggling with building a counter variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I have to do is count the number of years an employee has been in a certain position in a certain department, without counting the employees who were in that position previously. I only need continuous years of employment, if there is a break in employment, then I would only want to count from the most recent hire year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My variables are: year, department, position, emp_id,. After running a proc sql to pull the employees I ran a proc sort and then this data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data makegroup;
set match;
countvar +1;
by year department position emp_id;
if first.year then countvar=1;
run;&lt;/PRE&gt;
&lt;P&gt;This unfortunately starts a counter from 1 all the way to 40k+ ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The next step I have&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table want as 
select year, department, position, emp_id,
		count(countvar) as total_years
from makegroup
group by year, department, position, emp_id
having year = max(year)
order by year, department, position, emp_id
;
quit;&lt;/PRE&gt;
&lt;P&gt;Which is great except it gives me the employees that were previously in that position and it doesn't account for breaks in employment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be much appreciated! Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in this table there is a break between 0708 and 0910, so I want to count 9 years, instead my code counts for 12.&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;year&lt;/TD&gt;
&lt;TD&gt;department&lt;/TD&gt;
&lt;TD&gt;position&lt;/TD&gt;
&lt;TD&gt;emp_id&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;506&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;607&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;708&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;910&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1011&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1112&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1213&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1314&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1415&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1516&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1617&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1718&lt;/TD&gt;
&lt;TD&gt;sales&lt;/TD&gt;
&lt;TD&gt;assist&lt;/TD&gt;
&lt;TD&gt;ls3891g&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&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>Thu, 08 Feb 2018 19:41:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435398#M282025</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-08T19:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: Counter variable with filters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435404#M282026</link>
      <description>Now that I look at it again putting multiple conditions in the if statement like Reeza is saying is the best way. To fix the last part it would be really easy just to make a year4 field and do all the conditions in there if first.emp_id r and first.year4 then countvar=1; .</description>
      <pubDate>Thu, 08 Feb 2018 19:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435404#M282026</guid>
      <dc:creator>Larrihoover</dc:creator>
      <dc:date>2018-02-08T19:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: Counter variable with filters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435414#M282027</link>
      <description>&lt;P&gt;Even with this solution, my counter is still saying 12 instead of 9&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 20:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435414#M282027</guid>
      <dc:creator>serrld113</dc:creator>
      <dc:date>2018-02-08T20:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: Counter variable with filters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435422#M282028</link>
      <description>&lt;P&gt;Post your code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What would you expect from the sample data you provided above?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that's all of your data what would the output look like.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 20:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435422#M282028</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-08T20:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Counter variable with filters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435425#M282029</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input year department $ position $ emp_id $;
datalines;
506 sales assist ls3891g 
607 sales assist ls3891g 
708 sales assist ls3891g 
910 sales assist ls3891g 
1011 sales assist ls3891g 
1112 sales assist ls3891g 
1213 sales assist ls3891g 
1314 sales assist ls3891g 
1415 sales assist ls3891g 
1516 sales assist ls3891g 
1617 sales assist ls3891g 
1718 sales assist ls3891g 
;
run;

data makegroup;
set test;
by year department position emp_id;
if first.emp_id then countvar=1;
countvar +1;
run;

proc sql;
create table counts2 as 
select department, position, emp_id, count(countvar) as totalyears from makegroup
group by department, position, emp_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;department&lt;/TD&gt;&lt;TD&gt;position&lt;/TD&gt;&lt;TD&gt;emp_id&lt;/TD&gt;&lt;TD&gt;totalyears&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would expect it to look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;department&lt;/TD&gt;&lt;TD&gt;position&lt;/TD&gt;&lt;TD&gt;emp_id&lt;/TD&gt;&lt;TD&gt;totalyears&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;TD&gt;assist&lt;/TD&gt;&lt;TD&gt;ls3891g&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 20:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435425#M282029</guid>
      <dc:creator>serrld113</dc:creator>
      <dc:date>2018-02-08T20:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Counter variable with filters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435432#M282030</link>
      <description>&lt;P&gt;You can't quite do it that easily. It sounds like you're looking for the longest continuous employment it seems for each employee or the last stretch, not sure because you only have one example so can't generalize.&lt;/P&gt;
&lt;P&gt;You need to convert your dates to SAS dates to make this work and then check for continuity.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There may be easier ways to do this with PROC TIMESERIES.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="delete_counter.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18406i0C48599763AD141B/image-size/large?v=v2&amp;amp;px=999" role="button" title="delete_counter.JPG" alt="delete_counter.JPG" /&gt;&lt;/span&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 20:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/435432#M282030</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-08T20:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Counter variable with filters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/437102#M282031</link>
      <description>&lt;P&gt;I ended up doing a proc transpose...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc transpose data = testin out = testout;
by department position emp_id;
var year;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then a proc sort followed by this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testout;
set testout;
else if col1 = 1718 and col2 = 1617 and col3 = 1516 and col4 = 1415 and col5 = 1314 and col6 = 1213 then consec_years = 6;
else if col1 = 1718 and col2 = 1617 and col3 = 1516 and col4 = 1415 and col5 = 1314 then consec_years = 5;
else if col1 = 1718 and col2 = 1617 and col3 = 1516 and col4 = 1415 then consec_years = 4;
else if col1 = 1718 and col2 = 1617 and col3 = 1516 then consec_years = 3;
else if col1 = 1718 and col2 = 1617 then consec_years = 2;
else if col1 = 1718 then consec_years = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully this will help anybody else with the same problem as me. Thank you to everybody that helped out&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 14:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-variable-with-filters/m-p/437102#M282031</guid>
      <dc:creator>serrld113</dc:creator>
      <dc:date>2018-02-14T14:46:48Z</dc:date>
    </item>
  </channel>
</rss>

