<?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: Making calculations across rows in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/341556#M10171</link>
    <description>&lt;P&gt;Are you using data integratation studio?&lt;/P&gt;</description>
    <pubDate>Thu, 16 Mar 2017 12:45:51 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-03-16T12:45:51Z</dc:date>
    <item>
      <title>Making calculations across rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/341553#M10169</link>
      <description>&lt;DIV class="post-text"&gt;&lt;P&gt;Quick question:&lt;/P&gt;&lt;P&gt;In a table with lots of operations in which I have unique identifiers (concatenating date and operation ID), how can I choose to calculate the change between the amount of one month and the previous one? (Assuming that the rows are never next to each other since there are lots of different operations and dates).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically, telling the code to take the amount of the row with a specific date and operation, and substract it from another specific row with another date and operation&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 16 Mar 2017 12:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/341553#M10169</guid>
      <dc:creator>pablorodriguez1</dc:creator>
      <dc:date>2017-03-16T12:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: Making calculations across rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/341556#M10171</link>
      <description>&lt;P&gt;Are you using data integratation studio?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 12:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/341556#M10171</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-16T12:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Making calculations across rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/341557#M10172</link>
      <description>&lt;P&gt;First of all, are you trying to do that in DI Studio or just with manually written code?&lt;/P&gt;
&lt;P&gt;(You might have posted into the wrong community, I can move your post if needed)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, please use the macro provided in &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; to convert your example data into a data step for posting here, and post it into a {i} or "little running man" window.&lt;/P&gt;
&lt;P&gt;This allows us to recreate your data with a simple copy/paste and run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are several ways to achieve what you have in mind. One uses a sort that brings your observations into an order where the observations to be compared follow each other immediately; another uses a hash object to keep values to be compared in memory.&lt;/P&gt;
&lt;P&gt;One can also use SQL to remerge the dataset with itself, depending on the proper condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which option is best can be determined upon dataset structure and size (a hash object might run out of memory, SQL could get you dismal performance).&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 12:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/341557#M10172</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-16T12:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: Making calculations across rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/341584#M10174</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Divide Alice's Height by Williams Weight

This is what IML or IML interface with R is meant to solve

HAVE
====

Up to 40 obs from sd1.class total obs=19

Obs    NAME       SEX    AGE    HEIGHT    WEIGHT

  1    Alfred      M      14     69.0      112.5
  2    Alice       F      13     56.5*      84.0
                                 -----
  3    Barbara     F      13     65.3       98.0
  4    Carol       F      14     62.8      102.5
  5    Henry       M      14     63.5      102.5
  6    James       M      12     57.3       83.0
  7    Jane        F      12     59.8       84.5
  8    Janet       F      15     62.5      112.5
  9    Jeffrey     M      13     62.5       84.0
 10    John        M      12     59.0       99.5
 11    Joyce       F      11     51.3       50.5
 12    Judy        F      14     64.3       90.0
 13    Louise      F      12     56.3       77.0
 14    Mary        F      15     66.5      112.0
 15    Philip      M      16     72.0      150.0
 16    Robert      M      12     64.8      128.0
 17    Ronald      M      15     67.0      133.0
 18    Thomas      M      11     57.5       85.0
 19    William     M      15     66.5      112.0* WANT   56.5/112.0
                                           -----

WANT

  [1] 0.5044643


WORKING CODE

     res&amp;lt;-have$Height[have$Name=="Alice"]/have$Weight[have$Name=="William"];

FULL SOLUTION

Cut and paste code into IML interface with R or use IML directly

%utl_submit_wps64('
libname sd1 "d:/sd1";
options set=R_HOME "C:/Program Files/R/R-3.3.2";
libname wrk "%sysfunc(pathname(work))";
libname hlp "C:\Program Files\SASHome\SASFoundation\9.4\core\sashelp";

data sd1.class;
  set hlp.class;
run;quit;

proc r;
submit;
source("C:/Program Files/R/R-3.3.2/etc/Rprofile.site", echo=T);
library(haven);
have&amp;lt;-read_sas("d:/sd1/class.sas7bdat");
have;
res&amp;lt;-have$Height[have$Name=="Alice"]/have$Weight[have$Name=="William"];
res;
endsubmit;
');

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 14:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/341584#M10174</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-16T14:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Making calculations across rows</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/343332#M10220</link>
      <description>&lt;P&gt;Pablo,&lt;/P&gt;&lt;P&gt;I think an SQL solution could work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
&amp;nbsp; select
&amp;nbsp; &amp;nbsp; current.ID,
&amp;nbsp; &amp;nbsp; intnx('MONTH',current.date,1) as StartOfMonth,
&amp;nbsp; &amp;nbsp; current.amount-previous.amount as ChangeAmount
&amp;nbsp; from have current join have previous
&amp;nbsp; &amp;nbsp; on have.ID=previous.ID
&amp;nbsp; &amp;nbsp; &amp;nbsp; and intck('MONTH',previous.date,current.date)=1
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or something like that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Søren.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 15:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Making-calculations-across-rows/m-p/343332#M10220</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-03-22T15:28:24Z</dc:date>
    </item>
  </channel>
</rss>

