<?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 values in two rows in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371222#M24232</link>
    <description>&lt;P&gt;Please dont post all in upper case. &amp;nbsp;Are you using code for this? &amp;nbsp;If so then you can do two things:&lt;/P&gt;
&lt;P&gt;retain: &amp;nbsp;retain values across rows - in this example val1 will contain the first val data across the dataset.&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  retain val1;
  if _n_=1 then val1=val;
run;&lt;/PRE&gt;
&lt;P&gt;lagX() function: with this you can look back X number of rows:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  test=value-lag5(value);
run;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Jun 2017 11:43:18 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-06-28T11:43:18Z</dc:date>
    <item>
      <title>Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371215#M24228</link>
      <description>&lt;P&gt;HOW TO CALCULATE THE DIFFERENCE WITH IN THE COLUMNS LIKE "GAP DIFFERENCE" = (2ND ROW VALUE -1 ST ROW&amp;nbsp;VALUE)&amp;nbsp;FOR n NUMBER OF SUBSEQUENT ROWS.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 11:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371215#M24228</guid>
      <dc:creator>mrinmoynano</dc:creator>
      <dc:date>2017-06-28T11:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371216#M24229</link>
      <description>1&lt;BR /&gt;2 1&lt;BR /&gt;3 2&lt;BR /&gt;4 3&lt;BR /&gt;5 4&lt;BR /&gt;6 5&lt;BR /&gt;6</description>
      <pubDate>Wed, 28 Jun 2017 11:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371216#M24229</guid>
      <dc:creator>mrinmoynano</dc:creator>
      <dc:date>2017-06-28T11:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371220#M24231</link>
      <description>&lt;P&gt;Please don't shout at us (writing all capitals).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To compare with the preceding observation, use the lag() function.&lt;/P&gt;
&lt;P&gt;To compare with a specific previous value, use a retained variable that is set whenever a new group starts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For further help, please post example data in a data step like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input value;
cards;
1
2
3
4
5
6
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jun 2017 11:41:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371220#M24231</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-28T11:41:52Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371222#M24232</link>
      <description>&lt;P&gt;Please dont post all in upper case. &amp;nbsp;Are you using code for this? &amp;nbsp;If so then you can do two things:&lt;/P&gt;
&lt;P&gt;retain: &amp;nbsp;retain values across rows - in this example val1 will contain the first val data across the dataset.&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  retain val1;
  if _n_=1 then val1=val;
run;&lt;/PRE&gt;
&lt;P&gt;lagX() function: with this you can look back X number of rows:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  test=value-lag5(value);
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jun 2017 11:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371222#M24232</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-28T11:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371235#M24233</link>
      <description>&lt;P&gt;The simplest way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;difference = dif(varname);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One trick to the DIF function:&amp;nbsp; apply it on every observation.&amp;nbsp; Even if you don't want DIFFERENCE calculated all the time, apply it anyway.&amp;nbsp; You can always wipe out DIFFERENCE later if you need to with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if /* some condition here */ then difference = .;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 12:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371235#M24233</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-28T12:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371448#M24239</link>
      <description>&lt;P&gt;You really need to indicate the input data separately from the output. We can't tell if you may be adding rows or not;&lt;/P&gt;
&lt;P&gt;It appears that you are actually comparing to the first value not to the previous value. In which case you need to keep the first value.&lt;/P&gt;
&lt;P&gt;Here is one way to do at least part of what I think you are attempting. Notice the use of a different sequence of values. Your orginal example has many other ways to create without involving any other row in any way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input value;
datalines;
1
2 
5 
4 
9 
6 
;
run;

data want;
   set have;
   retain base;
   if _n_=1 then base=value;
   else difference = value-base;
   drop base;
run;&lt;/PRE&gt;
&lt;P&gt;The _n_ is a special variable related to the row of the data set. In this case when = 1 then it is the first row and we set the base value to keep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 19:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371448#M24239</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-28T19:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371515#M24247</link>
      <description>&lt;P&gt;only on SAS Enterprise guide.... without code&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13999iE244FE1FAE7A7CFD/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="2017-06-29 08_50_58-Solved_ Difference between values in two rows - SAS Support Communities.png" title="2017-06-29 08_50_58-Solved_ Difference between values in two rows - SAS Support Communities.png" /&gt;</description>
      <pubDate>Thu, 29 Jun 2017 03:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371515#M24247</guid>
      <dc:creator>mrinmoynano</dc:creator>
      <dc:date>2017-06-29T03:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371527#M24248</link>
      <description>&lt;P&gt;thank you for the reply. Since I am new in code in sas . can you do other methodology in sas enterprise guide using query builder and write an expression &amp;nbsp;to get the result .&lt;/P&gt;&lt;P&gt;problem &amp;nbsp;description: I have one column with&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Value&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;160&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;180&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;We need to generate a new column called Difference as the following table&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Value&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Difference&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;160&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;180&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 05:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371527#M24248</guid>
      <dc:creator>mrinmoynano</dc:creator>
      <dc:date>2017-06-29T05:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371528#M24249</link>
      <description>&lt;P&gt;data want;&lt;BR /&gt;WORK.QUERY_FOR_APPEND_TABLE_0002;&lt;BR /&gt;difference = dif(Pyrometer Channel01);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;error&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR&lt;BR /&gt;24&lt;BR /&gt;25 GOPTIONS ACCESSIBLE;&lt;BR /&gt;26 data want;&lt;BR /&gt;27 WORK.QUERY_FOR_APPEND_TABLE_0002;&lt;BR /&gt;________________________________&lt;BR /&gt;557&lt;BR /&gt;ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.&lt;BR /&gt;ERROR 557-185: Variable WORK is not an object.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 05:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371528#M24249</guid>
      <dc:creator>mrinmoynano</dc:creator>
      <dc:date>2017-06-29T05:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371530#M24250</link>
      <description>&lt;P&gt;You missed the set keyword in your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set work.query_for_append_table_0002;
difference = dif(Pyrometer Channel01);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jun 2017 05:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371530#M24250</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-29T05:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371541#M24253</link>
      <description>&lt;P&gt;still has some problem. Please check&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/14002i704EDE7BB56302BA/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="2017-06-29 11_58_54-Summary Statistics update1 - SAS Enterprise Guide.png" title="2017-06-29 11_58_54-Summary Statistics update1 - SAS Enterprise Guide.png" /&gt;</description>
      <pubDate>Thu, 29 Jun 2017 06:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371541#M24253</guid>
      <dc:creator>mrinmoynano</dc:creator>
      <dc:date>2017-06-29T06:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371543#M24255</link>
      <description>&lt;P&gt;That's simply because&lt;/P&gt;
&lt;PRE&gt;Pyrometer Channel01&lt;/PRE&gt;
&lt;P&gt;is not a valid SAS name.&lt;/P&gt;
&lt;P&gt;The dif() function only accepts one variable (missed that when I copied your code).&lt;/P&gt;
&lt;P&gt;AND PLEASE DO NOT POST TEXT AS PICTURES!&lt;/P&gt;
&lt;P&gt;Use the {i} button (the 6th on top of the posting window) to post text from logs etc.&lt;/P&gt;
&lt;P&gt;The 7th button is good for SAS code.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 06:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371543#M24255</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-29T06:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between values in two rows</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371576#M24257</link>
      <description>&lt;P&gt;Thank you It is working now&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 08:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difference-between-values-in-two-rows/m-p/371576#M24257</guid>
      <dc:creator>mrinmoynano</dc:creator>
      <dc:date>2017-06-29T08:45:25Z</dc:date>
    </item>
  </channel>
</rss>

