<?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: Calculate difference between current month and previou month balance in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641231#M191089</link>
    <description>Hi. Yes I cantry this. Just that its a huge dataset of half a million records and 27 date columns.&lt;BR /&gt;&lt;BR /&gt;Hence wa trying to know any function or soething&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
    <pubDate>Mon, 20 Apr 2020 09:56:47 GMT</pubDate>
    <dc:creator>Sandy10</dc:creator>
    <dc:date>2020-04-20T09:56:47Z</dc:date>
    <item>
      <title>Calculate difference between current month and previou month balance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641226#M191085</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SA dataset as below. Customer ID and their MoM balance(Apr17- Monthyear). I wnat to calculate growth in each month. i.e, May growth is&amp;nbsp;SAV_May17-SAV-Apr17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Customer ID&lt;/TD&gt;&lt;TD&gt;SAV_APR17&lt;/TD&gt;&lt;TD&gt;SAV_May17&lt;/TD&gt;&lt;TD&gt;SAV_Jun17&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CD&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Customer ID&lt;/TD&gt;&lt;TD&gt;May growth&lt;/TD&gt;&lt;TD&gt;Jun growth&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;-170&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CD&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to do this in SAS?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note that I can change column names.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and Regards&lt;/P&gt;&lt;P&gt;Sandhya S&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 09:39:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641226#M191085</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2020-04-20T09:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between current month and previou month balance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641229#M191087</link>
      <description>Hello, try this&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table output_data_set as&lt;BR /&gt;select&lt;BR /&gt;id&lt;BR /&gt;,(may-apr) as may_growth&lt;BR /&gt;,(jun-may) as jun_growth&lt;BR /&gt;from input_data_set&lt;BR /&gt;;quit&lt;BR /&gt;</description>
      <pubDate>Mon, 20 Apr 2020 09:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641229#M191087</guid>
      <dc:creator>Krabkvadrat</dc:creator>
      <dc:date>2020-04-20T09:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between current month and previou month balance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641231#M191089</link>
      <description>Hi. Yes I cantry this. Just that its a huge dataset of half a million records and 27 date columns.&lt;BR /&gt;&lt;BR /&gt;Hence wa trying to know any function or soething&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Mon, 20 Apr 2020 09:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641231#M191089</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2020-04-20T09:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between current month and previou month balance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641234#M191092</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;
input Customer_ID$ SAV_APR17 SAV_May17 SAV_Jun17;
cards;
A 100 200 30
B 200 300 500
CD 100 600 1000
;

data want;
set have;
array vals(3) SAV_APR17 SAV_May17 SAV_Jun17;
array vals2(3) may june july;
do i = 1 to 3;
if i&amp;lt;=3 then vals2(i)=vals(i)-vals(i+(i&amp;lt;3));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Apr 2020 10:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641234#M191092</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-20T10:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between current month and previou month balance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641240#M191096</link>
      <description>&lt;P&gt;You suffer from an unfavorable data structure; with a longitudinal structure, the code is a breeze:&lt;/P&gt;
&lt;P&gt;So let's first bring your wide dataset (probably coming from an Excel sheet) into form, and make SAS dates out of your columns names:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_wide;
input Customer_ID$ SAV_APR17 SAV_May17 SAV_Jun17;
cards;
A 100 200 30
B 200 300 500
CD 100 600 1000
;

proc transpose data=have_wide out=trans (rename=(col1=sav));
by customer_id;
var sav:;
run;

data have;
set trans;
period = input(substr(_name_,5),monyy5.);
format period yymms7.;
drop _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We then make sure that the dataset is sorted, and create the wanted result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by customer_id period;
run;

data want;
set have;
by customer_id;
growth = sav - lag(sav);
if first.customer_id then growth = .;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see how simple the data step that does all the work becomes, as soon as you have an intelligent data structure. See Maxims 19 &amp;amp; 33.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 10:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641240#M191096</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-20T10:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between current month and previou month balance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641249#M191101</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; Thanks a lot for your reply. I have a dataset which is about half a million customers&lt;BR /&gt;and 27 date columns. WIll this code be still quick and be used?</description>
      <pubDate>Mon, 20 Apr 2020 10:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641249#M191101</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2020-04-20T10:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between current month and previou month balance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641264#M191108</link>
      <description>&lt;P&gt;So you get 500000 * 27 observations, each having an observation size of&lt;/P&gt;
&lt;P&gt;length(id) + 8 (date) + 8(sav) + 8 (growth), or&lt;/P&gt;
&lt;P&gt;500000 * 27 * 34 (if id is 10 bytes long).&lt;/P&gt;
&lt;P&gt;This amounts to 459000000 bytes, or approx. 450 MB. That's puny in all respects (think: about 100 photos on the SD card of your high-res camera).&lt;/P&gt;
&lt;P&gt;You can even run such datasets through the rather limited University Edition.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 11:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641264#M191108</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-20T11:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between current month and previou month balance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641267#M191110</link>
      <description>&lt;P&gt;And think about this: in your wide dataset, each month for each customer will need space, even if the customer has no value for that month. In a long dataset, you can omit missing or zero observations, as in most calculations you will do you can use the date values to calculate the timespan between observations. That offsets the space needed for the additional date (period) column.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 11:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641267#M191110</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-20T11:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between current month and previou month balance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641319#M191120</link>
      <description>&lt;P&gt;Additionally the long form with an actual date value will allow things like graphs with date as the xaxis that the original data would not support.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date values also can create groups of values just by changing the format. If you want to get an average balance for a quarter use any of the report or summary functions with the date variable and change the format to yyQ. Or a calendar summary by using applying the YEAR format to the same report.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 14:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-between-current-month-and-previou-month/m-p/641319#M191120</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-20T14:23:53Z</dc:date>
    </item>
  </channel>
</rss>

