<?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: Month-on-Month Change in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428857#M27672</link>
    <description>&lt;P&gt;Thanks Reeza, I think I'll come back to this method when I'm a bit more capable&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jan 2018 16:25:44 GMT</pubDate>
    <dc:creator>jagnew</dc:creator>
    <dc:date>2018-01-18T16:25:44Z</dc:date>
    <item>
      <title>Month-on-Month Change</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428320#M27589</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table which is a list of transactions, with customer numbers and products.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to group transactions by customer and month and find the months where volume changes &amp;gt;10% vs the last month they transacted (which may be several months before).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideally the output would show Customer, Month, Volume, Change vs Last Month Traded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very new with SAS and have no idea how to do this, any help would be great.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jamie&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 10:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428320#M27589</guid>
      <dc:creator>jagnew</dc:creator>
      <dc:date>2018-01-17T10:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Month-on-Month Change</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428324#M27590</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest if you are new to SAS then start with the training material:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://video.sas.com/#category/videos/how-to-tutorials" target="_blank"&gt;http://video.sas.com/#category/videos/how-to-tutorials&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can follow this up by looking through the forums here, there is a lot of information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After that if you have further questions, then post a question here, supply test data in the form of a datastep (as we cannot see your data or structure) using the code window (which is the {i} above post area) and following this post if need:&lt;/P&gt;
&lt;P&gt;&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;&lt;/P&gt;
&lt;P&gt;Further, post example required output so we can inputs/outputs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At a guess from what you say you can do it in a number of ways, first group the data using proc means/summary, or with proc sql.&amp;nbsp; Then a datastep with a diff() and calculation.&amp;nbsp; E.g.&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table SUMMED as
  select  CUSTOMER,
             MONTH,
             sum(VOLUME) as VOLUME
  from   HAVE
  group by CUSTOMER,
                 MONTH;
quit;

data want;
  set summed;
  if lag(customer)=customer then change=diff(volume);
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jan 2018 11:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428324#M27590</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-17T11:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Month-on-Month Change</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428337#M27595</link>
      <description>&lt;P&gt;Thanks for your help, although I am still unsure how to proceed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I have from Query Builder, I need to add another column which is Auto% Change - this needs to be a measure of the change against the previous month for the customer, so should be blank/null for the first month for each customer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure how to use the DATA STEP.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_ALL_VOL_0000 AS 
   SELECT t1.CUSTOMER_NUM, 
          t1.YEAR, 
          t1.MONTH, 
          t1.'AUTO%'n
      FROM WORK.QUERY_FOR_ALL_VOL t1;
QUIT;&lt;/PRE&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 12:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428337#M27595</guid>
      <dc:creator>jagnew</dc:creator>
      <dc:date>2018-01-17T12:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Month-on-Month Change</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428382#M27599</link>
      <description>&lt;P&gt;You can put code in code blocks, I believe that there is an option to do these code blocks in EG.&amp;nbsp; Not used Query builder before, I prefer writing the code myself.&amp;nbsp; You can see from that generated code you are missing a sum() and a group by, how you get those in using QB I don't know, its far simpler to write the code into a code block following what I provided.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 14:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428382#M27599</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-17T14:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Month-on-Month Change</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428386#M27600</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=summed;
by customer_num year month;
run;

data want;
set summed;
by customer_num;
change_percent = auto_percent - lag(auto_percent);
if first.customer_num then change_percent = .;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You probably won't need the sort, depending on how you created the sum.&lt;/P&gt;
&lt;P&gt;Note that I don't use non-standard variable names like 'AUTO%'n. Special characters have their place in variable labels.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 14:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428386#M27600</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-17T14:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Month-on-Month Change</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428459#M27614</link>
      <description>&lt;P&gt;If you're going to use the GUI tools in EG you need to break things down into small steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Summarize the data to have&amp;nbsp;to get the&amp;nbsp;totals by customer/month -&amp;gt; Summarize Task or Query Builder&lt;/P&gt;
&lt;P&gt;2. Sort to ensure order is correct -&amp;gt; Sort Task or in Step 1 of Query Builder&lt;/P&gt;
&lt;P&gt;3. Calculate difference between last month -&amp;gt; data step is the only way I know, use either DIF or LAG function to obtain previous value&lt;/P&gt;
&lt;P&gt;5. Filter to include only records of interest -&amp;gt; not actually sure what you want here yet, but WHERE clause&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This also depends on how your data is stored.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're learning to code this is much simpler, something along the lines of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=have noprint nway;
class customer month;
var &amp;lt;your var&amp;gt;;
output out=summary_table1 sum(&amp;lt;your var&amp;gt;) = total_sales;
run;

proc sort data=summary_table1;
by customer month;
run;

data prev_value;
set summary_table1;
by customer;

prev_value = lag(total_sales);
if first.customer then prev_value = .;
 if prev_value ne . then want = total_sales/ prev_value -1;
run;

data want;
set prev_value;
where want &amp;gt; &amp;lt;threshold&amp;gt;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181639"&gt;@jagnew&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table which is a list of transactions, with customer numbers and products.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to group transactions by customer and month and find the months where volume changes &amp;gt;10% vs the last month they transacted (which may be several months before).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally the output would show Customer, Month, Volume, Change vs Last Month Traded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am very new with SAS and have no idea how to do this, any help would be great.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jamie&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 16:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428459#M27614</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-17T16:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Month-on-Month Change</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428784#M27663</link>
      <description>&lt;P&gt;Thanks, this has worked great.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a further step I would like to add another column in showing LAG2 (another step back). How can I change the 'if first' part to account for this - it would be 'if second' that I need but I don't think this is a function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 13:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428784#M27663</guid>
      <dc:creator>jagnew</dc:creator>
      <dc:date>2018-01-18T13:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: Month-on-Month Change</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428789#M27665</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181639"&gt;@jagnew&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, this has worked great.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a further step I would like to add another column in showing LAG2 (another step back). How can I change the 'if first' part to account for this - it would be 'if second' that I need but I don't think this is a function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Add a counter variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set summed;
by customer_num;
change_percent = auto_percent - lag(auto_percent);
change_percent_2 = auto_percent - lag2(auto_percent);
if first.customer_num
then do;
  counter = 1;
  change_percent = .;
  change_percent_2 = .;
end;
else do;
  counter + 1;
  if counter = 2 then change_percent_2 = .;
end;
drop counter;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The use of the increment syntax&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;counter + 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of the normal addition syntax&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;counter = counter + 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;makes SAS automatically retain the variable, otherwise a retain statement would be needed.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 14:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428789#M27665</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-18T14:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Month-on-Month Change</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428855#M27671</link>
      <description>&lt;P&gt;Thanks Kurt, much appreciated&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 16:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428855#M27671</guid>
      <dc:creator>jagnew</dc:creator>
      <dc:date>2018-01-18T16:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Month-on-Month Change</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428857#M27672</link>
      <description>&lt;P&gt;Thanks Reeza, I think I'll come back to this method when I'm a bit more capable&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 16:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Month-on-Month-Change/m-p/428857#M27672</guid>
      <dc:creator>jagnew</dc:creator>
      <dc:date>2018-01-18T16:25:44Z</dc:date>
    </item>
  </channel>
</rss>

