<?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: How do i create a counter to decrease on variable change rules in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519103#M140556</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input ID $	DATE_OF_VALUE :ddmmyy10.	VALUE	HAVE;
format DATE_OF_VALUE date9.;
cards;
109999999 05/12/2017 42376 1
109999999 05/12/2017 42376 2
109999999 13/12/2017 42521 1
109999999 13/12/2017 42521 2
109999999 19/03/2018 43395 1
109999999 19/03/2018 43395 2
109999999 19/03/2018 43395 3
109999999 19/03/2018 43395 4
109999999 04/06/2018 43953 1
109999999 04/06/2018 43953 2
109999999 17/09/2018 44899 1
109999999 17/09/2018 44899 2
;

proc sort data=have;
by id descending DATE_OF_VALUE;
run;

data want;
set have;
by id value notsorted;
temp+first.value; 
want=temp;
if not first.value then call missing(want);
drop temp;
run;

proc sort data=want;
by id DATE_OF_VALUE ;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Dec 2018 12:47:02 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-12-06T12:47:02Z</dc:date>
    <item>
      <title>How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519058#M140525</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm having trouble trying to get a counting variable to decreased based on the rules of other variables given to me by a client.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;currently, i have the "HAVE" column, but want to achieve the "WANT"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;we know there are 5 unique date changed for this ID, and ignoring the duplicate value on the same day - this would then show my i have 5 unqiue value changes over time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;DATE_OF_VALUE&lt;/TD&gt;&lt;TD&gt;VALUE&lt;/TD&gt;&lt;TD&gt;HAVE&lt;/TD&gt;&lt;TD&gt;WANT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;109999999&lt;/TD&gt;&lt;TD&gt;05/12/2017&lt;/TD&gt;&lt;TD&gt;42376&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;109999999&lt;/TD&gt;&lt;TD&gt;05/12/2017&lt;/TD&gt;&lt;TD&gt;42376&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;109999999&lt;/TD&gt;&lt;TD&gt;13/12/2017&lt;/TD&gt;&lt;TD&gt;42521&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;109999999&lt;/TD&gt;&lt;TD&gt;13/12/2017&lt;/TD&gt;&lt;TD&gt;42521&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;109999999&lt;/TD&gt;&lt;TD&gt;19/03/2018&lt;/TD&gt;&lt;TD&gt;43395&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;109999999&lt;/TD&gt;&lt;TD&gt;19/03/2018&lt;/TD&gt;&lt;TD&gt;43395&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;109999999&lt;/TD&gt;&lt;TD&gt;19/03/2018&lt;/TD&gt;&lt;TD&gt;43395&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;109999999&lt;/TD&gt;&lt;TD&gt;19/03/2018&lt;/TD&gt;&lt;TD&gt;43395&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;109999999&lt;/TD&gt;&lt;TD&gt;04/06/2018&lt;/TD&gt;&lt;TD&gt;43953&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;109999999&lt;/TD&gt;&lt;TD&gt;04/06/2018&lt;/TD&gt;&lt;TD&gt;43953&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;109999999&lt;/TD&gt;&lt;TD&gt;17Sep2018&lt;/TD&gt;&lt;TD&gt;44899&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;109999999&lt;/TD&gt;&lt;TD&gt;17Sep2018&lt;/TD&gt;&lt;TD&gt;44899&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the code i have for the "HAVE" column looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can someone please help me achieve the "WANT" column, as i'm having issues with sorting and the BY statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data TEST1;&lt;BR /&gt; set TEST;&lt;BR /&gt;&lt;BR /&gt; by ID VALUE &lt;SPAN&gt;DATE_OF_VALUE&lt;/SPAN&gt;;&lt;BR /&gt;&lt;BR /&gt; if first.VALUE and first.DATE_OF_VALUE then do;&lt;BR /&gt; HAVE=1;&lt;BR /&gt; end;&lt;BR /&gt;&lt;BR /&gt; else do ;&lt;BR /&gt; HAVE+1;&lt;BR /&gt; end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;i want to try and achieve this in one step if possible&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 09:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519058#M140525</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2018-12-06T09:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519060#M140526</link>
      <description>&lt;P&gt;To start with, dont code in upppercase.&amp;nbsp; Anyways this should work:&lt;/P&gt;
&lt;PRE&gt;data test1;&lt;BR /&gt;  set test;&lt;BR /&gt;  by id value date_of_value;&lt;BR /&gt;  retain want;&lt;BR /&gt;  if first.id then want=5;&lt;BR /&gt;  else if first.date_of_value then want=want-1;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;Also, post test data in the form of a datastep in future, not here to type that in.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 09:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519060#M140526</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-06T09:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519061#M140527</link>
      <description>&lt;P&gt;Please post data as datastep using datalines and add at least a second id, so that we can verify our ideas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would start by sorting by id and decreasing "date_of_value", than start with want=1 and increment it when "value" changes. You can either add a variable and retain its value, or you can use lag-function to get older values of "value".&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 09:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519061#M140527</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-12-06T09:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519062#M140528</link>
      <description>Thank you for looking at this so promptly - i'm just looking at the forum posting rules now</description>
      <pubDate>Thu, 06 Dec 2018 09:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519062#M140528</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2018-12-06T09:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519074#M140538</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input ID $	DATE_OF_VALUE :ddmmyy10.	VALUE	HAVE;
format DATE_OF_VALUE date9.;
cards;
109999999 05/12/2017 42376 1
109999999 05/12/2017 42376 2
109999999 13/12/2017 42521 1
109999999 13/12/2017 42521 2
109999999 19/03/2018 43395 1
109999999 19/03/2018 43395 2
109999999 19/03/2018 43395 3
109999999 19/03/2018 43395 4
109999999 04/06/2018 43953 1
109999999 04/06/2018 43953 2
109999999 17/09/2018 44899 1
109999999 17/09/2018 44899 2
;

proc sort data=have;
by id descending DATE_OF_VALUE have;
run;

data want;
set have;
by id descending DATE_OF_VALUE have;

if first.DATE_OF_VALUE  then _want+1;
if first.DATE_OF_VALUE and _want ne . then want=_want;
drop _want;
run;

proc sort data=want;
by id DATE_OF_VALUE ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Dec 2018 10:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519074#M140538</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-06T10:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519077#M140541</link>
      <description>&lt;P&gt;thank you for the replies, i'm just getting the datalines done and a few more ID's to show change&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;each date and value can be duplicated but the same value can repeat to a different date too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
    LENGTH
        ID 8 DATE_OF_VALUE $10 VALUE 8 HAVE 8 WANT 8 ;
    FORMAT
        ID 9. DATE_OF_VALUE $10. VALUE 5. HAVE 1. WANT 1. ;
    INFORMAT
        ID 9. DATE_OF_VALUE $10. VALUE 5. HAVE 1. WANT 1. ;
    INFILE DATALINES4
        DLM=','
        MISSOVER
        DSD ;
    INPUT
        ID : 9. DATE_OF_VALUE : $10. VALUE: 5. HAVE: 1.WANT : 1. ;
DATALINES4;
109999999,05/12/2017,42376,1,5
109999999,05/12/2017,42376,2,.
109999999,13/12/2017,42521,1,4
109999999,13/12/2017,42521,2,.
109999999,19/03/2018,43395,1,3
109999999,19/03/2018,43395,2,.
109999999,19/03/2018,43395,3,.
109999999,19/03/2018,43395,4,.
109999999,04/06/2018,43953,1,2
109999999,04/06/2018,43953,2,.
109999999,17/09/2018,44899,1,1
109999999,17/09/2018,44899,2,.
109999998,21/04/2018,4788,1,2
109999998,21/04/2018,4788,2,.
109999998,01/06/2018,4788,3,.
109999998,01/06/2018,4788,4,.
109999998,23/09/2018,4718,1,1
109999998,23/09/2018,4718,2,.
109999997,09/07/2018,8717,1,2
109999997,09/07/2018,8717,2,.
109999997,01/09/2018,8750,1,1
109999997,01/09/2018,8750,2,.
109999995,15/02/2018,22868,1,2
109999995,15/02/2018,22868,2,.
109999995,07/09/2018,22631,1,1
109999995,07/09/2018,22631,2,.
109554995,05/12/2017,92376,1,5
109554995,05/12/2017,92376,2,.
109554995,13/12/2017,92521,1,4
109554995,13/12/2017,92521,2,.
109554995,19/03/2018,93395,1,3
109554995,19/03/2018,93395,2,.
109554995,19/03/2018,93395,3,.
109554995,19/03/2018,93395,4,.
109554995,04/06/2018,93953,1,2
109554995,04/06/2018,93953,2,.
109554995,11/07/2018,94953,1,1
;;;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Dec 2018 10:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519077#M140541</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2018-12-06T10:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519079#M140543</link>
      <description>Hi Jag, thanks for the reply, i have added some datalines above, we need ignore HAVE this was just my first attempt</description>
      <pubDate>Thu, 06 Dec 2018 10:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519079#M140543</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2018-12-06T10:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519081#M140544</link>
      <description>&lt;P&gt;Its just good practice not to shout code, hence using lower case.&amp;nbsp; As for the data you present, it doesn't seem to match your original request.&amp;nbsp; You first start by saying you know there is 5 occurrences, however this test data clearly shows less than 5 instances in some cases?&amp;nbsp; So which is it?&amp;nbsp; Do you need to find out how many there are first, say a quick SQL count(distinct), then merge that information back on?&amp;nbsp; So assuming want is present and the first per id shows total (note your test data also seems to show various levels of changes, i.e. obs15, should change as the date is different, but doesnt?):&lt;/P&gt;
&lt;PRE&gt;data test;
  length id 8 date_of_value $10 value 8 have 8 want 8;
  infile datalines4 dlm=',' missover dsd;
  input id date_of_value $ value have want;
datalines4;
109999999,05/12/2017,42376,1,5
109999999,05/12/2017,42376,2,.
109999999,13/12/2017,42521,1,4
109999999,13/12/2017,42521,2,.
109999999,19/03/2018,43395,1,3
109999999,19/03/2018,43395,2,.
109999999,19/03/2018,43395,3,.
109999999,19/03/2018,43395,4,.
109999999,04/06/2018,43953,1,2
109999999,04/06/2018,43953,2,.
109999999,17/09/2018,44899,1,1
109999999,17/09/2018,44899,2,.
109999998,21/04/2018,4788,1,2
109999998,21/04/2018,4788,2,.
109999998,01/06/2018,4788,3,.
109999998,01/06/2018,4788,4,.
109999998,23/09/2018,4718,1,1
109999998,23/09/2018,4718,2,.
109999997,09/07/2018,8717,1,2
109999997,09/07/2018,8717,2,.
109999997,01/09/2018,8750,1,1
109999997,01/09/2018,8750,2,.
109999995,15/02/2018,22868,1,2
109999995,15/02/2018,22868,2,.
109999995,07/09/2018,22631,1,1
109999995,07/09/2018,22631,2,.
109554995,05/12/2017,92376,1,5
109554995,05/12/2017,92376,2,.
109554995,13/12/2017,92521,1,4
109554995,13/12/2017,92521,2,.
109554995,19/03/2018,93395,1,3
109554995,19/03/2018,93395,2,.
109554995,19/03/2018,93395,3,.
109554995,19/03/2018,93395,4,.
109554995,04/06/2018,93953,1,2
109554995,04/06/2018,93953,2,.
109554995,11/07/2018,94953,1,1
;;;;
run;

data test1;
  set test;
  by id date_of_value notsorted;
  retain count;
  if first.id then count=want;
  else if first.date_of_value then count=count-1;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 11:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519081#M140544</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-06T11:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519086#M140546</link>
      <description>the HAVE value is where i attempted to create a counter myself, and should not be used in the solution.&lt;BR /&gt;&lt;BR /&gt;i apologise if i didn't explain correctly, the maximum is not 5, this was just present for that ID, it can go to any number, but the min will always be 1.&lt;BR /&gt;&lt;BR /&gt;the WANT and HAVE in my dataset can be ignored.&lt;BR /&gt;&lt;BR /&gt;the change you talk about is only a change in the date, but the value remains the same, so ignored.&lt;BR /&gt;&lt;BR /&gt;if we wanted to know the max it would have to be for each ID, VALUE and DATE being unique</description>
      <pubDate>Thu, 06 Dec 2018 11:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519086#M140546</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2018-12-06T11:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519088#M140547</link>
      <description>Did you test the code on the added data lines. you need not use the have variable.</description>
      <pubDate>Thu, 06 Dec 2018 11:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519088#M140547</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-06T11:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519089#M140548</link>
      <description>&lt;P&gt;i wanted to show an example of my workings&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 11:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519089#M140548</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2018-12-06T11:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519092#M140550</link>
      <description>if you add all the cases i proved in the datalines, you will see your example works on the first set of ID, then continues to increment on other ID's not starting again from 1</description>
      <pubDate>Thu, 06 Dec 2018 12:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519092#M140550</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2018-12-06T12:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519094#M140551</link>
      <description>&lt;P&gt;Hi, its seems where the numbers are placed are correct just the values are&amp;nbsp;not as they should be&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="WANT.PNG" style="width: 341px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25411iECB7AA6E9F2ADCAA/image-size/large?v=v2&amp;amp;px=999" role="button" title="WANT.PNG" alt="WANT.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 12:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519094#M140551</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2018-12-06T12:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519097#M140553</link>
      <description>Wanted to check if you tested by code on this data &lt;BR /&gt;</description>
      <pubDate>Thu, 06 Dec 2018 12:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519097#M140553</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-06T12:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519100#M140554</link>
      <description>&lt;P&gt;apolozies for this data please try this code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  length id 8   value 8 have 8;
  infile datalines4 dlm=',' missover dsd;
  input id date_of_value :ddmmyy10. value have ;
  format date_of_value date9.;
datalines4;
109999999,05/12/2017,42376,1
109999999,05/12/2017,42376,2
109999999,13/12/2017,42521,1
109999999,13/12/2017,42521,2
109999999,19/03/2018,43395,1
109999999,19/03/2018,43395,2
109999999,19/03/2018,43395,3
109999999,19/03/2018,43395,4
109999999,04/06/2018,43953,1
109999999,04/06/2018,43953,2
109999999,17/09/2018,44899,1
109999999,17/09/2018,44899,2
109999998,21/04/2018,4788,1
109999998,21/04/2018,4788,2
109999998,01/06/2018,4788,3
109999998,01/06/2018,4788,4
109999998,23/09/2018,4718,1
109999998,23/09/2018,4718,2
109999997,09/07/2018,8717,1
109999997,09/07/2018,8717,2
109999997,01/09/2018,8750,1
109999997,01/09/2018,8750,2
109999995,15/02/2018,22868,1
109999995,15/02/2018,22868,2
109999995,07/09/2018,22631,1
109999995,07/09/2018,22631,2
109554995,05/12/2017,92376,1
109554995,05/12/2017,92376,2
109554995,13/12/2017,92521,1
109554995,13/12/2017,92521,2
109554995,19/03/2018,93395,1
109554995,19/03/2018,93395,2
109554995,19/03/2018,93395,3
109554995,19/03/2018,93395,4
109554995,04/06/2018,93953,1
109554995,04/06/2018,93953,2
109554995,11/07/2018,94953,1
;;;;
run;

proc sort data=test;
by id descending DATE_OF_VALUE have;
run;

data want;
set test;
by id descending DATE_OF_VALUE have;

if first.id then _want=.;
if first.DATE_OF_VALUE then _want+1;

if first.DATE_OF_VALUE and _want ne . then want=_want;
drop _want;
run;

proc sort data=want;
by id DATE_OF_VALUE ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Dec 2018 12:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519100#M140554</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-06T12:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519103#M140556</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input ID $	DATE_OF_VALUE :ddmmyy10.	VALUE	HAVE;
format DATE_OF_VALUE date9.;
cards;
109999999 05/12/2017 42376 1
109999999 05/12/2017 42376 2
109999999 13/12/2017 42521 1
109999999 13/12/2017 42521 2
109999999 19/03/2018 43395 1
109999999 19/03/2018 43395 2
109999999 19/03/2018 43395 3
109999999 19/03/2018 43395 4
109999999 04/06/2018 43953 1
109999999 04/06/2018 43953 2
109999999 17/09/2018 44899 1
109999999 17/09/2018 44899 2
;

proc sort data=have;
by id descending DATE_OF_VALUE;
run;

data want;
set have;
by id value notsorted;
temp+first.value; 
want=temp;
if not first.value then call missing(want);
drop temp;
run;

proc sort data=want;
by id DATE_OF_VALUE ;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Dec 2018 12:47:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519103#M140556</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-12-06T12:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do i create a counter to decrease on variable change rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519104#M140557</link>
      <description>THIS IS PERFECT!!!&lt;BR /&gt;&lt;BR /&gt;i had no idea you can process first. twice&lt;BR /&gt;&lt;BR /&gt;it turns out my mistake creating the counter in WANT actually helped.&lt;BR /&gt;&lt;BR /&gt;Thank you</description>
      <pubDate>Thu, 06 Dec 2018 12:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-create-a-counter-to-decrease-on-variable-change-rules/m-p/519104#M140557</guid>
      <dc:creator>teelov</dc:creator>
      <dc:date>2018-12-06T12:59:19Z</dc:date>
    </item>
  </channel>
</rss>

