<?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: Difference between row values within multiple groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585027#M166754</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268817"&gt;@crawfe&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I was careless! I called it Var1,2. I should have called it Label1, Label2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example a Before/After comparison.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Still haven't actually described the role in the output. You don't show either value in the "want".&lt;/P&gt;
&lt;P&gt;So it sounds like you may want to go back and revisit what your actual desired output should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And consider if it is all possible that you have 3 or more identical name values or only one. If so, what output do you want for those cases?&lt;/P&gt;</description>
    <pubDate>Thu, 29 Aug 2019 18:24:41 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-08-29T18:24:41Z</dc:date>
    <item>
      <title>Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585007#M166743</link>
      <description>&lt;P&gt;Hi. Row-row calculations seem tougher in SAS...&lt;/P&gt;&lt;P&gt;I need to calculate the difference and % difference between values in adjacent rows (Var2-Var1 values)&lt;/P&gt;&lt;P&gt;but only within specific Name groups. Thanks for any ideas!&lt;/P&gt;&lt;P&gt;I would like to do it within EG but if I need to run a separate program and join back, I will.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Want:&lt;/P&gt;&lt;P&gt;&amp;nbsp; Name &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Difference&amp;nbsp;&amp;nbsp;&amp;nbsp; %Dif&lt;/P&gt;&lt;P&gt;Name1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name1 &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -50%&lt;/P&gt;&lt;P&gt;Name1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; Name2 &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; - 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -75%&lt;/P&gt;&lt;P&gt;Name2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 25%&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;etc. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 17:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585007#M166743</guid>
      <dc:creator>crawfe</dc:creator>
      <dc:date>2019-08-29T17:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585013#M166746</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268817"&gt;@crawfe&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi. Row-row calculations seem tougher in SAS...&lt;/P&gt;
&lt;P&gt;I need to calculate the difference and % difference between values in adjacent rows (Var2-Var1 values)&lt;/P&gt;
&lt;P&gt;but only within specific Name groups. Thanks for any ideas!&lt;/P&gt;
&lt;P&gt;I would like to do it within EG but if I need to run a separate program and join back, I will.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Name &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Difference&amp;nbsp;&amp;nbsp;&amp;nbsp; %Dif&lt;/P&gt;
&lt;P&gt;Name1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name1 &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -50%&lt;/P&gt;
&lt;P&gt;Name1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; Name2 &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; - 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -75%&lt;/P&gt;
&lt;P&gt;Name2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 25%&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;etc. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You really need to provide some details what the Var values play in this scenario. Such as are there ever values other than Var1, Var2? If so provide an example of the data and what the result should be in that case.&lt;/P&gt;
&lt;P&gt;What you show does not involve the value of the variable Var at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Providing data in the form of data step helps resolve questions about actual variable names and types. Paste into a code box to preserve formatting of code and values as the message windows my reformat code or data such that it will not actually run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to do this:&lt;/P&gt;
&lt;PRE&gt;data have;
   input name $ value;
datalines;
A 4
A 2
B 8
B 2
C 4
C 5
;
 
data want;
   set have;
   by name;
   lv= lag(value);
   dv= dif(value);
   if not (first.name) then do;
      dif = DV;
      pct = dv/lv;
      output;
   end;
   keep name dif pct;
run;

   
&lt;/PRE&gt;
&lt;P&gt;Assumes the data is sorted by name. If you have multiple values of Name (more than 2) you will get difference per sequential pair. If there is only one name value the code above will not output the name as there is no difference to calculate.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 17:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585013#M166746</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-29T17:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585016#M166748</link>
      <description>&lt;P&gt;Please try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
inut Name$ Var$ Value;
cards;        
Name1 Var1  4            
Name1 Var2  2            
Name2 Var1   8              
Name2 Var2   2             
Name3 Var1  4                  
Name3 var2  5  
;

proc sort data=have;
by name var;
run;

data want;
set have;
by name var;
if first.name then sum=value;
else sum+value;
dif=value-lag(value);
pct=(value-lag(value))/lag(value);
if first.name then do;dif=.;pct=.;end;
if last.name;
format pct percentn.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2019 18:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585016#M166748</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-29T18:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585017#M166749</link>
      <description>&lt;P&gt;I was careless! I called it Var1,2. I should have called it Label1, Label2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example a Before/After comparison.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 18:03:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585017#M166749</guid>
      <dc:creator>crawfe</dc:creator>
      <dc:date>2019-08-29T18:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585027#M166754</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268817"&gt;@crawfe&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I was careless! I called it Var1,2. I should have called it Label1, Label2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example a Before/After comparison.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Still haven't actually described the role in the output. You don't show either value in the "want".&lt;/P&gt;
&lt;P&gt;So it sounds like you may want to go back and revisit what your actual desired output should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And consider if it is all possible that you have 3 or more identical name values or only one. If so, what output do you want for those cases?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 18:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585027#M166754</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-29T18:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585037#M166761</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268817"&gt;@crawfe&lt;/a&gt; are there always 2 records for each calculation?&lt;/P&gt;
&lt;P&gt;if so then the solutions provided work.&lt;/P&gt;
&lt;P&gt;If not then the solutions provided may give unexpected results if your data is like this.&lt;/P&gt;
&lt;PRE&gt;data have;
input Name$ Var$ Value;
cards;        
Name1 Var1  4            
Name1 Var2  2
&lt;STRONG&gt;Name1 Var3  1&lt;/STRONG&gt; 
Name2 Var1   8              
Name2 Var2   2             
Name3 Var1  4                  
Name3 var2  5  
;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2019 18:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585037#M166761</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-08-29T18:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585061#M166773</link>
      <description>&lt;P&gt;LOL. I was just going to mention that. The code is just right if my table is perfectly symmetric.&lt;/P&gt;&lt;P&gt;Browsing my table, I see cases similar to what you&lt;/P&gt;&lt;P&gt;mention where there is not always a pair of Names to calculate the difference or percent change.&lt;/P&gt;&lt;P&gt;Apparently, if there was no input, there was no line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will apparently have to put in a few IF-THEN patches&lt;/P&gt;&lt;P&gt;like if pct ="" then pct = 100% (or -100% depending on the before/after flag). &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
input Name$ Var$ Value;
cards;        
Name1 Before  4            
Name1 After   2
Name2 Before  8              
Name2 After   2 &lt;BR /&gt;&lt;STRONG&gt;Name3 After   3&lt;/STRONG&gt;            
Name4 Before  4                  
Name4 After   5 &lt;BR /&gt;&lt;STRONG&gt;Name5 Before  6&lt;/STRONG&gt;&lt;BR /&gt;Name6 Before  3&lt;BR /&gt;Name6 After   1
;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 19:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585061#M166773</guid>
      <dc:creator>crawfe</dc:creator>
      <dc:date>2019-08-29T19:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585062#M166774</link>
      <description>&lt;P&gt;so you can try the below code, same as i posted before but with slight changes as per the new data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name$ Var$ Value;
if var='Before' then varn=1;
else if var='After' then varn=1;
cards;        
Name1 Before  4            
Name1 After   2
Name2 Before  8              
Name2 After   2 
Name3 After   3            
Name4 Before  4                  
Name4 After   5 
Name5 Before  6
Name6 Before  3
Name6 After   1
;

proc sort data=have;
by name varn;
run;

data want;
set have;
by name varn;
if first.name then sum=value;
else sum+value;
dif=value-lag(value);
pct=(value-lag(value))/lag(value);
if first.name then do;dif=.;pct=.;end;
if last.name;
format pct percentn.;
drop sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2019 19:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585062#M166774</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-29T19:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585078#M166784</link>
      <description>&lt;P&gt;Perhaps reshaping the data would simplify things:&lt;/P&gt;
&lt;P&gt;Again assuming sort by Name and no more than two possible values of Var:&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have
   out=trans;
   by name;
   id var;
   var value;
run;&lt;/PRE&gt;
&lt;P&gt;Now you have two variables name Before and After with the values of Value assigned. Use a data step to calculate on the row. This would allow likely simpler coding for what to do with either the Before or After missing (not to mention the potential divide by 0 from no change that hadn't been addressed yet).&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 20:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585078#M166784</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-29T20:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585101#M166798</link>
      <description>&lt;P&gt;This should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name$ Var$ Value;
cards;        
Name1 Before  4            
Name1 After   2
Name2 Before  8              
Name2 After   2 
Name3 After   3            
Name4 Before  4                  
Name4 After   5 
Name5 Before  6
Name6 Before  3
Name6 After   1
;

data want;
merge have(where=(Var="Before") rename=Value=Value1)
    have(where=(Var="After") rename=Value=Value2);
by Name;
if nmiss(Value1, value2) = 0 then do;
    difference = Value2-Value1;
    PctDiff = Difference / Value1;
    end;
format pctDiff percentn7.1;
keep name difference pctDiff;
run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                           Name     difference    PctDiff

                           Name1        -2        -50.0%
                           Name2        -6        -75.0%
                           Name3         .           .
                           Name4         1         25.0%
                           Name5         .           .
                           Name6        -2        -66.7%
&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2019 22:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585101#M166798</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-08-29T22:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585170#M166825</link>
      <description>&lt;P&gt;Interesting. I have never seen transpose before. I can see how it could be useful. Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2019 11:49:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585170#M166825</guid>
      <dc:creator>crawfe</dc:creator>
      <dc:date>2019-08-30T11:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between row values within multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585171#M166826</link>
      <description>&lt;P&gt;Several good solution variations here. Thanks!!&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2019 11:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-row-values-within-multiple-groups/m-p/585171#M166826</guid>
      <dc:creator>crawfe</dc:creator>
      <dc:date>2019-08-30T11:50:47Z</dc:date>
    </item>
  </channel>
</rss>

