<?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: Calculations over rows for each customer in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778998#M248051</link>
    <description>&lt;P&gt;That's what I left for you to do. From the information in the data set named STATS, you can tell which group each customer is in.&lt;/P&gt;</description>
    <pubDate>Sun, 07 Nov 2021 16:47:16 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-11-07T16:47:16Z</dc:date>
    <item>
      <title>Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778988#M248044</link>
      <description>Hello&lt;BR /&gt;For each customer there is follow up of maximum 12 months.&lt;BR /&gt;(It means that the follow up period can be lower than 12 months but cannot be more than 12 months).&lt;BR /&gt;In each period there is information of score (A-best score.....E-worse score).&lt;BR /&gt;Score in time 0 is base score and then there is follow up (of maximum 12 months)&amp;amp;nbsp;&lt;BR /&gt;I want to create a new data set (called wanted) with one row for each customer with the following columns:&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;1-Score in base month (time 0)&lt;BR /&gt;Expected values:&lt;BR /&gt;For ID=1 :base&amp;amp;nbsp;is A&lt;BR /&gt;For ID=2 :base&amp;amp;nbsp;is B&lt;BR /&gt;For ID=3 :base&amp;amp;nbsp;is C&lt;BR /&gt;For ID=4 :base&amp;amp;nbsp;is D&lt;BR /&gt;For ID=5 :base&amp;amp;nbsp;is A&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;2-Max score over the follow up period(Follow up is in time 1 till 12)&lt;BR /&gt;Expected values:&lt;BR /&gt;For ID=1 :Max is A&lt;BR /&gt;For ID=2 :Max is D&lt;BR /&gt;For ID=3 :Max is C&lt;BR /&gt;For ID=4 :Max is E&lt;BR /&gt;For ID=5 :Max is E&lt;BR /&gt;For ID=6 :Max is C&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;3-Last Score&amp;amp;nbsp;&lt;BR /&gt;For ID=1 :Last&amp;amp;nbsp;is A&lt;BR /&gt;For ID=2 :Last&amp;amp;nbsp;is D&lt;BR /&gt;For ID=3 :Last&amp;amp;nbsp;is C&lt;BR /&gt;For ID=4 :Last&amp;amp;nbsp;is E&lt;BR /&gt;For ID=5 :Last&amp;amp;nbsp;is A&lt;BR /&gt;For ID=5 :Last&amp;amp;nbsp;is B&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;4-Classify each customer ID for one of the following groups:&lt;BR /&gt;Group_1: Customer stay in same score over time(so scores in times 0,1,2,3,4,5,6,7,8,9,10,11,12 are same)&lt;BR /&gt;For example: ID 1,3&lt;BR /&gt;Group_2: Customer go to worse score and stay there&lt;BR /&gt;For example: ID 2&lt;BR /&gt;Group_3: Customer go to better score and stay there&lt;BR /&gt;For example: ID 6&lt;BR /&gt;Group_4: There are at least 2 changes in scores over time and last score is better/same&amp;amp;nbsp; than score in time 1&lt;BR /&gt;For example: ID 5&lt;BR /&gt;Group_4: There are at least 2 changes in scores over time and last score is worse than score in time 1&lt;BR /&gt;For example: ID 4&lt;BR /&gt;&amp;amp;nbsp;&lt;BR /&gt;5-Number of changes in score from time 0 till time 12</description>
      <pubDate>Sun, 07 Nov 2021 16:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778988#M248044</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-11-07T16:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778992#M248046</link>
      <description>&lt;PRE&gt;1 12 A2 0 B&lt;/PRE&gt;
&lt;P&gt;What does this row in your input data mean? What is A2? what is the 0 and B on this row?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Shouldn't there be 3 variables (or more?) in your input statement? Can you fix this?&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 15:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778992#M248046</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-07T15:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778995#M248048</link>
      <description>Please  see the raw data.&lt;BR /&gt;Data have;&lt;BR /&gt;Input ID time score $;&lt;BR /&gt;2 0 B&lt;BR /&gt;2 1 B&lt;BR /&gt;2 2 D&lt;BR /&gt;3 0 C&lt;BR /&gt;3 1 C&lt;BR /&gt;3 2 C&lt;BR /&gt;4 0 D&lt;BR /&gt;4 1 C&lt;BR /&gt;4 2 C&lt;BR /&gt;4 3 C&lt;BR /&gt;4 4 D&lt;BR /&gt;4 5 D&lt;BR /&gt;4 6 E&lt;BR /&gt;5 0 B&lt;BR /&gt;5 1 B&lt;BR /&gt;5 2 E&lt;BR /&gt;5 3 B&lt;BR /&gt;6 0 C&lt;BR /&gt;6 1 C&lt;BR /&gt;6 2 C &lt;BR /&gt;6 3 C&lt;BR /&gt;6 4 B&lt;BR /&gt;6 5 B&lt;BR /&gt;6 6 B&lt;BR /&gt;1 0 A&lt;BR /&gt;1 1 A&lt;BR /&gt;1 2 A &lt;BR /&gt;1 3 A&lt;BR /&gt;1 4 A&lt;BR /&gt;1 5 A&lt;BR /&gt;1 6 A&lt;BR /&gt;1 7 A&lt;BR /&gt;1 8 A&lt;BR /&gt;1 9 A&lt;BR /&gt;1 10 A&lt;BR /&gt;1 11 A&lt;BR /&gt;1 12 A&lt;BR /&gt;;&lt;BR /&gt;Run;</description>
      <pubDate>Sun, 07 Nov 2021 16:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778995#M248048</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-11-07T16:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778996#M248049</link>
      <description>&lt;P&gt;Your code still doesn't work. I would be delighted if, in the future, you could provide working code instead of expecting us to debug basic code like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
	set have;
	by id notsorted;
	if score='A' then score2=1;
	else if score='B' then score2=2;
	else if score='C' then score2=3;
	else if score='D' then score2=4;
	else if score='E' then score2=5;
	if first.id then first_score=score2;
	if last.id then last_score=score2;
	prevscore2=lag(score2);
	if not first.id and score2^=prevscore2 then change=1;
run;

proc summary data=have2 nway;
	class id;
	var change first_score last_score;
	output out=stats sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From the output data set named STATS, you can create the categories for each ID, which I leave up to you.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 16:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778996#M248049</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-07T16:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778997#M248050</link>
      <description>This solution is great but what about the most complicated new field.&lt;BR /&gt;Classify each customer ID for one of the following groups:&lt;BR /&gt;Group_1: Customer stay in same score over time&lt;BR /&gt;&lt;BR /&gt;Group_2: Customer go to worse score and stay there&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Group_3: Customer go to better score and stay there&lt;BR /&gt;&lt;BR /&gt;Group_4: There are at least 2 changes in scores over time and last score is better/same than score  in time 0&lt;BR /&gt;&lt;BR /&gt;Group_4: There are at least 2 changes in scores over time and last score is worse than score in time 0</description>
      <pubDate>Sun, 07 Nov 2021 16:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778997#M248050</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-11-07T16:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778998#M248051</link>
      <description>&lt;P&gt;That's what I left for you to do. From the information in the data set named STATS, you can tell which group each customer is in.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 16:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778998#M248051</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-07T16:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778999#M248052</link>
      <description>Please  see the wanted classifications:&lt;BR /&gt;&lt;BR /&gt;2 "get worse "&lt;BR /&gt;2 0 B&lt;BR /&gt;2 1 B&lt;BR /&gt;2 2 D&lt;BR /&gt;Customer 3 "stay same"&lt;BR /&gt;3 0 C&lt;BR /&gt;3 1 C&lt;BR /&gt;3 2 C&lt;BR /&gt;Customer  4 " more than 1 change and get worse "&lt;BR /&gt;4 0 D&lt;BR /&gt;4 1 C&lt;BR /&gt;4 2 C&lt;BR /&gt;4 3 C&lt;BR /&gt;4 4 D&lt;BR /&gt;4 5 D&lt;BR /&gt;4 6 E&lt;BR /&gt;Customer  5 "more than 1 change stay same or better "&lt;BR /&gt;5 0 B&lt;BR /&gt;5 1 B&lt;BR /&gt;5 2 E&lt;BR /&gt;5 3 B&lt;BR /&gt;Customer  6 "get better "&lt;BR /&gt;6 0 C&lt;BR /&gt;6 1 C&lt;BR /&gt;6 2 C&lt;BR /&gt;6 3 C&lt;BR /&gt;6 4 B&lt;BR /&gt;6 5 B&lt;BR /&gt;6 6 B&lt;BR /&gt;Customer  1 "stay same"&lt;BR /&gt;1 0 A&lt;BR /&gt;1 1 A&lt;BR /&gt;1 2 A&lt;BR /&gt;1 3 A&lt;BR /&gt;1 4 A&lt;BR /&gt;1 5 A&lt;BR /&gt;1 6 A&lt;BR /&gt;1 7 A&lt;BR /&gt;1 8 A&lt;BR /&gt;1 9 A&lt;BR /&gt;1 10 A&lt;BR /&gt;1 11 A&lt;BR /&gt;1 12 A</description>
      <pubDate>Sun, 07 Nov 2021 16:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/778999#M248052</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-11-07T16:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779003#M248055</link>
      <description>&lt;P&gt;Just for fun, maybe like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
Input ID time score $;
cards;
2 0 B
2 1 B
2 2 D
3 0 C
3 1 C
3 2 C
4 0 D
4 1 C
4 2 C
4 3 C
4 4 D
4 5 D
4 6 E
5 0 B
5 1 B
5 2 E
5 3 B
6 0 C
6 1 C
6 2 C
6 3 C
6 4 B
6 5 B
6 6 B
1 0 A
1 1 A
1 2 A
1 3 A
1 4 A
1 5 A
1 6 A
1 7 A
1 8 A
1 9 A
1 10 A
1 11 A
1 12 A
;
run;

/* [EDIT] */
data want;

  do until (last.id);
    set have;
    by id score notsorted;

    if first.id then first.scr=rank(score)-64;
    if last.id  then last.scr =rank(score)-64;

    change + first.score;
  end;
    
    change + -1;
    wb = sign(last.scr-first.scr);
    
    classification = catx(" ", ifc(change, "more than 1 change " !! ifc(wb&amp;gt;0, " get worse", " get better or stay same")
                                         , ifc(wb&amp;gt;0, "get worse", ifc(wb&amp;lt;0, "get better", "stay same"))) );
  output;

  change = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 19:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779003#M248055</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-11-07T19:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779012#M248058</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Please see the wanted classifications:&lt;BR /&gt;&lt;BR /&gt;2 "get worse "&lt;BR /&gt;2 0 B&lt;BR /&gt;2 1 B&lt;BR /&gt;2 2 D
&lt;P class="1636315346964"&gt;etc.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;All the information you need to create these categories is now in the data set named STATS. Did you actually look at the data set named STATS?? You should be able to take that information and create the categories in a minute or so. It's a homework assignment for you.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 20:05:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779012#M248058</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-07T20:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779017#M248059</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;May you please explain:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;first.scr=rank(score)-64;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;why did you write 64?&lt;/P&gt;
&lt;P&gt;What does it mean SCR?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 20:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779017#M248059</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-11-07T20:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779018#M248060</link>
      <description>Thanks,&lt;BR /&gt;I thinks that in order to assign to category need to know 2 things:&lt;BR /&gt;1- Number of changes&lt;BR /&gt;2-First Score VS last score(same/better/worse)&lt;BR /&gt;</description>
      <pubDate>Sun, 07 Nov 2021 20:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779018#M248060</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-11-07T20:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779020#M248062</link>
      <description>May you please explain the code?</description>
      <pubDate>Sun, 07 Nov 2021 20:30:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779020#M248062</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-11-07T20:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779023#M248065</link>
      <description>&lt;P&gt;The rank() function returns number of character in ASCII table, rank("A") is 65, rank("B") is 66, etc. so&amp;nbsp;rank("A")-64 gives 1,&amp;nbsp;rank("B")-64 gives 2, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "first.src" and "last.scr" are just two temporary variables which will be automatically deleted from output from pdv, you can replace them by first_src and last_src and add DROP into the code and you will get the same effect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;B.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 20:38:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779023#M248065</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-11-07T20:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779024#M248066</link>
      <description>&lt;P&gt;When I thought about it I see it can be even simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;

  do until (last.id);
    set have;
    by id score notsorted;

    if first.id then first.scr=rank(score);
    if last.id  then last.scr =rank(score);

    change + first.score;
  end;
    
    change + -1;
    wb = last.scr-first.scr;
    
    classification = catx(" ", ifc(change, "more than 1 change " !! ifc(wb&amp;gt;0, " get worse", " get better or stay same")
                                         , ifc(wb&amp;gt;0, "get worse", ifc(wb&amp;lt;0, "get better", "stay same"))) );
  output;
  change = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;B.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 20:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779024#M248066</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-11-07T20:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779026#M248068</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks,&lt;BR /&gt;I thinks that in order to assign to category need to know 2 things:&lt;BR /&gt;1- Number of changes&lt;BR /&gt;2-First Score VS last score(same/better/worse)&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are very consistent at writing words without expressing what your question is. What is your question?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please answer my earlier question: did you actually look at the data set named STATS? If so, what did you see in there?&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 20:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779026#M248068</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-07T20:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779080#M248097</link>
      <description>&lt;P&gt;Here is another solution which is more verbose but easier to understand (I think) than the one suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                        
  do until(last.id);                                              
    set have;                                                     
    n_change+(score ne lag(score));  /* the LAG function must be called every time */                             
    by id notsorted;                                              
    if first.id then do;                                          
      score0=score;                                               
      n_change=0;                                                 
      end;                                                        
    end;                                                          
  select(n_change);                                               
    when(0) group=1; /* stays same */                             
    when(1) do;                                                   
      if score&amp;gt;score0 then group=2; /* higher value means worse */
      else group=3; /* score got better */                        
      end;                                                        
    otherwise do;                                                 
      if score&amp;gt;score0 then group=5; /* higher value means worse */
      else group=4; /* score got better or stayed the same */     
      end;                                                        
    end;                                                          
  keep id group n_change score score0;                            
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Nov 2021 09:11:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779080#M248097</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-11-08T09:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779114#M248111</link>
      <description>&lt;PRE&gt;Data have;
Input ID time score $;
cards;
2 0 B
2 1 B
2 2 D
3 0 C
3 1 C
3 2 C
4 0 D
4 1 C
4 2 C
4 3 C
4 4 D
4 5 D
4 6 E
5 0 B
5 1 B
5 2 E
5 3 B
6 0 C
6 1 C
6 2 C
6 3 C
6 4 B
6 5 B
6 6 B
1 0 A
1 1 A
1 2 A
1 3 A
1 4 A
1 5 A
1 6 A
1 7 A
1 8 A
1 9 A
1 10 A
1 11 A
1 12 A
;


data want;
change=0;
do until(last.id);
 set have;
 by id score notsorted;
 if first.id then first=score;
 change+first.score;
end;

length classification $ 40;
if change=1 then classification="stay same";
else if change=2 then do; 
                        if first&amp;lt;score then classification='get worse';
                          else  classification='get better';
                      end;
 else if change&amp;gt;2 then do;
                        if first&amp;lt;score then classification='more than 1 change and get worse';
                          else  classification='more than 1 change stay same or better';
                      end;
keep id classification;
run;



&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Nov 2021 13:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779114#M248111</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-11-08T13:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779143#M248115</link>
      <description>&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Data set&amp;nbsp;&lt;SPAN&gt;STATS helped and I am using it to calssify each customer to the correct group.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you again&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 15:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779143#M248115</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-11-08T15:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779289#M248161</link>
      <description>&lt;P&gt;Hi Ksharp!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good idea just to use first.score instead of the LAG function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only one suggestion: If you set CHANGE=-1 in the beginning of the DATA WANT datastep, you get the actual number of changes, which I think was also one of the data originally wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 10:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779289#M248161</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-11-09T10:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations over rows for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779302#M248163</link>
      <description>Agree! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 09 Nov 2021 11:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-over-rows-for-each-customer/m-p/779302#M248163</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-11-09T11:54:29Z</dc:date>
    </item>
  </channel>
</rss>

