<?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: Summing by 2 other variables as part of a formula in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298916#M60360</link>
    <description>&lt;P&gt;Thanks, this looks good, I think. Trying it out, and I'm getting some errors. Here is the log (note that the variable names are somewhat different, and&amp;nbsp;that there is a lot of code before (including the data import) which I've left out). I think if I fix line 462 it may work. Note that there may be some inconsistencies there, I had to change a couple of variable names and such due to posting publicly.&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;===&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data COMBINED_DATA;&lt;/P&gt;&lt;P&gt;455 set COMBINED_DATA;&lt;/P&gt;&lt;P&gt;456 temp_trans_date = mdy(trans_mo,01,trans_yr) ;&lt;/P&gt;&lt;P&gt;457 run;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;NOTE: There were 43528 observations read from the data set WORK.COMBINED_DATA.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.COMBINED_DATA has 43528 observations and 56 variables.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.07 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.08 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;458&lt;/P&gt;&lt;P&gt;459 proc sql;&lt;/P&gt;&lt;P&gt;460 create table tr_sum as select&lt;/P&gt;&lt;P&gt;461 CH_ID, temp_trans_date&lt;/P&gt;&lt;P&gt;462 sum(debit_amt) as tr_sum&lt;/P&gt;&lt;P&gt;___&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;76&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN,&lt;/P&gt;&lt;P&gt;CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;463 from combined_data&lt;/P&gt;&lt;P&gt;464 group by CH_ID, temp_trans_date&lt;/P&gt;&lt;P&gt;465 order by CH_ID, temp_trans_date descending;&lt;/P&gt;&lt;P&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;&lt;P&gt;466 quit;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;467&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;468 data tr_flag;&lt;/P&gt;&lt;P&gt;469 set tr_sum;&lt;/P&gt;&lt;P&gt;ERROR: File WORK.TR_SUM.DATA does not exist.&lt;/P&gt;&lt;P&gt;470 by CH_ID trans_mo descending;&lt;/P&gt;&lt;P&gt;_&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.&lt;/P&gt;&lt;P&gt;471 if first.CH_ID then flag1=0; else&lt;/P&gt;&lt;P&gt;472 if tr_sum &amp;gt; 1.5*(lag(tr_sum)) then flag1 = 1;&lt;/P&gt;&lt;P&gt;473 else flag1=0;&lt;/P&gt;&lt;P&gt;474 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;WARNING: The data set WORK.TR_FLAG may be incomplete. When this step was stopped there were 0 observations and 2 variables.&lt;/P&gt;&lt;P&gt;WARNING: Data set WORK.TR_FLAG was not replaced because this step was stopped.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;475&lt;/P&gt;&lt;P&gt;476 proc sql;&lt;/P&gt;&lt;P&gt;477 create table trans_new as select&lt;/P&gt;&lt;P&gt;478 t.*, s.flag1&lt;/P&gt;&lt;P&gt;479 from COMBINED_DATA as t&lt;/P&gt;&lt;P&gt;480 left join tr_sum as s&lt;/P&gt;&lt;P&gt;481 on t.CH_ID = s.CH_ID and&lt;/P&gt;&lt;P&gt;482 t.trans_mo = s.trans_mo&lt;/P&gt;&lt;P&gt;483 order by trans_ID, CH_ID, trans_yr, trans_mo;&lt;/P&gt;&lt;P&gt;ERROR: File WORK.TR_SUM.DATA does not exist.&lt;/P&gt;&lt;P&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;&lt;P&gt;483 ! /* adapt it to your needs */&lt;/P&gt;&lt;P&gt;484 quit;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2016 11:44:23 GMT</pubDate>
    <dc:creator>ZDR</dc:creator>
    <dc:date>2016-09-16T11:44:23Z</dc:date>
    <item>
      <title>Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298711#M60346</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;New to these boards, relatively new to BASE SAS. I'm trying to figure out how to create a formula that checks if the sum of multiple transactions for a particular user are above a certain threshold (in this case than the total for the previous month), and flags if so. The logic is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;flag_variable = IF((SUM(transaction_value) BY user_id AND month) &amp;gt; (SUM(transaction_value) BY user_id AND month-1) THEN 1 ELSE 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So essentially I'm trying to check if transactions for a particular user last month are greater than this month, and write the variable value as 1 if so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TRANSACTION_ID,TRANSACTION_VALUE,USER,MONTH,FLAG_VARIABLE&lt;/P&gt;&lt;P&gt;123,$30,001,5,0&lt;/P&gt;&lt;P&gt;124,$150,002,6,1&lt;/P&gt;&lt;P&gt;125,$25,001,6,0&lt;/P&gt;&lt;P&gt;126,$99,002,5,0&lt;/P&gt;&lt;P&gt;127,$55,001,5,0&lt;/P&gt;&lt;P&gt;128,$10,002,5,0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you can see I have multiple users conducting multiple transactions over multiple months. I want to sum the amount transacted per user per month, compare it to last month, and flag if it has increased. In this case, the flag_variable value for transaction_ID 124 would be 1, because total transaction value for user 002 has increased from month 5 to month 6.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure there is a simple way to do this but I'm new at this and haven't found anything online that does this specifically. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 16:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298711#M60346</guid>
      <dc:creator>ZDR</dc:creator>
      <dc:date>2016-09-15T16:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298747#M60348</link>
      <description>&lt;P&gt;Its not exactly clear what you want as final output. Do you want that flag on each transaction even though you've summed them up?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. You have to sum by month and user id -&amp;gt; Proc means/summary/univariate or Proc SQL&lt;/P&gt;
&lt;P&gt;2. Sort by UserID - month descending&lt;/P&gt;
&lt;P&gt;3. Use LAG() function to compare to previous months values and determine flag&lt;/P&gt;
&lt;P&gt;4. Merge back in with original data if desired.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 18:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298747#M60348</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-15T18:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298750#M60349</link>
      <description>&lt;P&gt;Few steps to achieve your target:&lt;/P&gt;&lt;P&gt;1) Import data into sas dataset. Are your transactions already in a sas table ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if not - what kind of file is it ? CSV / excel / other ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Sum transactions value per user, each month in different variable (sum01, sum02, ...sum12).&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;How many months are in the data file ?&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Do you have transactions of different years in same data file ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; If yes, you need a year beyond the month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; Thus can be done either by SQL or by base sas;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Th help you we need your answers to the above questions.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 18:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298750#M60349</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-09-15T18:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298762#M60350</link>
      <description>&lt;P&gt;Thanks, Shmuel. Replies to your questions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Data comes from a csv file with many other fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Currently about 6 months, over 2 years (2015 and 2016)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am indifferent to using base SAS or SQL, so whatever works best. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 19:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298762#M60350</guid>
      <dc:creator>ZDR</dc:creator>
      <dc:date>2016-09-15T19:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298764#M60351</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply. I want that flag on each transaction on the original dataset. So I don't need to keep those sums, I just need to calculate them to determine whether to flag or not. So the final result will not be a summary table or any sort of report, just an additional column on the original dataset with either 0 or 1 next to each transaction.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 19:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298764#M60351</guid>
      <dc:creator>ZDR</dc:creator>
      <dc:date>2016-09-15T19:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298786#M60352</link>
      <description>&lt;P&gt;/* step 1 - importing the data into sas */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename &amp;nbsp;trans CSV 'C:\ &amp;nbsp;...path to and file name... .CSV';&lt;/P&gt;&lt;P&gt;data trans;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;infile trans dlm=',' truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;input&amp;nbsp;&lt;SPAN&gt;TRANSACTION_ID &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TRANSACTION_VALUE&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; USER&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MONTH&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; YEAR&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; transaction_month = mdy(month, 01, year); &amp;nbsp;/* create a date variable */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/* step 2 - summarizing */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;create table tr_sum as select&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;user, transaction_month&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum(transaction_value) as tr_sum&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from trans&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;group by user, transaction_month &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;order by user, transaction_month descending;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/* step 3 - calculating the flag */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data tr_flag;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; set tr_sum;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; by user transaction_month descending;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if first.user then flag=0; else&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if tr_sum &amp;gt; lag(tr_sum) then flag = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else flag=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/* step 4 - merging the flag in the original dataset */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; create table trans_new as select&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t.*, s.flag&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from trans as t&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left join tr_sum as s&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;on t.user = s.user and&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t.transaction_month = s.transaction_month&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;order by&amp;nbsp;TRANSACTION_ID, USER, &amp;nbsp;year, MONTH; &amp;nbsp; &amp;nbsp;/* adapt it to your needs */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 20:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298786#M60352</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-09-15T20:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298916#M60360</link>
      <description>&lt;P&gt;Thanks, this looks good, I think. Trying it out, and I'm getting some errors. Here is the log (note that the variable names are somewhat different, and&amp;nbsp;that there is a lot of code before (including the data import) which I've left out). I think if I fix line 462 it may work. Note that there may be some inconsistencies there, I had to change a couple of variable names and such due to posting publicly.&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;===&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data COMBINED_DATA;&lt;/P&gt;&lt;P&gt;455 set COMBINED_DATA;&lt;/P&gt;&lt;P&gt;456 temp_trans_date = mdy(trans_mo,01,trans_yr) ;&lt;/P&gt;&lt;P&gt;457 run;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;NOTE: There were 43528 observations read from the data set WORK.COMBINED_DATA.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.COMBINED_DATA has 43528 observations and 56 variables.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.07 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.08 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;458&lt;/P&gt;&lt;P&gt;459 proc sql;&lt;/P&gt;&lt;P&gt;460 create table tr_sum as select&lt;/P&gt;&lt;P&gt;461 CH_ID, temp_trans_date&lt;/P&gt;&lt;P&gt;462 sum(debit_amt) as tr_sum&lt;/P&gt;&lt;P&gt;___&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;76&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN,&lt;/P&gt;&lt;P&gt;CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;463 from combined_data&lt;/P&gt;&lt;P&gt;464 group by CH_ID, temp_trans_date&lt;/P&gt;&lt;P&gt;465 order by CH_ID, temp_trans_date descending;&lt;/P&gt;&lt;P&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;&lt;P&gt;466 quit;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;467&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;468 data tr_flag;&lt;/P&gt;&lt;P&gt;469 set tr_sum;&lt;/P&gt;&lt;P&gt;ERROR: File WORK.TR_SUM.DATA does not exist.&lt;/P&gt;&lt;P&gt;470 by CH_ID trans_mo descending;&lt;/P&gt;&lt;P&gt;_&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.&lt;/P&gt;&lt;P&gt;471 if first.CH_ID then flag1=0; else&lt;/P&gt;&lt;P&gt;472 if tr_sum &amp;gt; 1.5*(lag(tr_sum)) then flag1 = 1;&lt;/P&gt;&lt;P&gt;473 else flag1=0;&lt;/P&gt;&lt;P&gt;474 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;WARNING: The data set WORK.TR_FLAG may be incomplete. When this step was stopped there were 0 observations and 2 variables.&lt;/P&gt;&lt;P&gt;WARNING: Data set WORK.TR_FLAG was not replaced because this step was stopped.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;475&lt;/P&gt;&lt;P&gt;476 proc sql;&lt;/P&gt;&lt;P&gt;477 create table trans_new as select&lt;/P&gt;&lt;P&gt;478 t.*, s.flag1&lt;/P&gt;&lt;P&gt;479 from COMBINED_DATA as t&lt;/P&gt;&lt;P&gt;480 left join tr_sum as s&lt;/P&gt;&lt;P&gt;481 on t.CH_ID = s.CH_ID and&lt;/P&gt;&lt;P&gt;482 t.trans_mo = s.trans_mo&lt;/P&gt;&lt;P&gt;483 order by trans_ID, CH_ID, trans_yr, trans_mo;&lt;/P&gt;&lt;P&gt;ERROR: File WORK.TR_SUM.DATA does not exist.&lt;/P&gt;&lt;P&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;&lt;P&gt;483 ! /* adapt it to your needs */&lt;/P&gt;&lt;P&gt;484 quit;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 11:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298916#M60360</guid>
      <dc:creator>ZDR</dc:creator>
      <dc:date>2016-09-16T11:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298934#M60363</link>
      <description>&lt;P&gt;Pay attemtion: variables list, while in SAS data step are seperated by space, while in SQL are seperated by comma.&lt;/P&gt;&lt;P&gt;Error on line 462 (in log) is becase you missed comma between&amp;nbsp;"temp_trans_date" and sum(debit_amt) ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On second thought, change sort type and drop the "descending" (on 2 lines); &amp;nbsp;(The default is "ascending");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Most of other errors seem to be the result of the first one.&lt;/P&gt;&lt;P&gt;Try it again and check, do you get expected results.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 13:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/298934#M60363</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-09-16T13:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/299026#M60386</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still getting errors:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;459 data COMBINED_DATA;&lt;/P&gt;&lt;P&gt;460 set COMBINED_DATA;&lt;/P&gt;&lt;P&gt;461 temp_trans_date = mdy(trans_mo,01,trans_yr) ;&lt;/P&gt;&lt;P&gt;462 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 43528 observations read from the data set WORK.COMBINED_DATA.&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.COMBINED_DATA has 43528 observations and 56 variables.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.07 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.07 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;463&lt;/P&gt;&lt;P&gt;464 proc sql;&lt;/P&gt;&lt;P&gt;465 create table tr_sum as select&lt;/P&gt;&lt;P&gt;466 CH_ID, temp_trans_date,&lt;/P&gt;&lt;P&gt;467 sum(debit_amt) as tr_sum&lt;/P&gt;&lt;P&gt;468 from combined_pcard_data&lt;/P&gt;&lt;P&gt;469 group by CH_ID, temp_trans_date&lt;/P&gt;&lt;P&gt;470 order by CH_ID, temp_trans_date ;&lt;/P&gt;&lt;P&gt;NOTE: Table WORK.TR_SUM created, with 3400 rows and 3 columns.&lt;/P&gt;&lt;P&gt;471 quit;&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.05 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.11 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;472&lt;/P&gt;&lt;P&gt;473 data tr_flag;&lt;/P&gt;&lt;P&gt;474 set tr_sum;&lt;/P&gt;&lt;P&gt;475 by CH_ID trans_mo ;&lt;/P&gt;&lt;P&gt;476 if first.CH_ID then flag1=0; else&lt;/P&gt;&lt;P&gt;477 if tr_sum &amp;gt; 1.15*(lag(tr_sum)) then flag1 = 1;&lt;/P&gt;&lt;P&gt;478 else flag1=0;&lt;/P&gt;&lt;P&gt;479 run;&lt;/P&gt;&lt;P&gt;ERROR: BY variable trans_mo is not on input data set WORK.TR_SUM.&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;WARNING: The data set WORK.TR_FLAG may be incomplete. When this step was stopped there were 0 observations and 4 variables.&lt;/P&gt;&lt;P&gt;WARNING: Data set WORK.TR_FLAG was not replaced because this step was stopped.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;480&lt;/P&gt;&lt;P&gt;481 proc sql;&lt;/P&gt;&lt;P&gt;12 The SAS System 10:13 Tuesday, September 13, 2016&lt;/P&gt;&lt;P&gt;482 create table trans_new as select&lt;/P&gt;&lt;P&gt;483 t.*, s.flag1&lt;/P&gt;&lt;P&gt;484 from COMBINED_DATA as t&lt;/P&gt;&lt;P&gt;485 left join tr_sum as s&lt;/P&gt;&lt;P&gt;486 on t.CH_ID = s.CH_ID and&lt;/P&gt;&lt;P&gt;487 t.trans_mo = s.trans_mo&lt;/P&gt;&lt;P&gt;488 order by trans_ID, CH_ID, trans_yr, trans_mo;&lt;/P&gt;&lt;P&gt;ERROR: Column trans_mo could not be found in the table/view identified with the correlation name S.&lt;/P&gt;&lt;P&gt;ERROR: Column trans_mo could not be found in the table/view identified with the correlation name S.&lt;/P&gt;&lt;P&gt;ERROR: Column trans_mo could not be found in the table/view identified with the correlation name S.&lt;/P&gt;&lt;P&gt;ERROR: Column flag1 could not be found in the table/view identified with the correlation name S.&lt;/P&gt;&lt;P&gt;ERROR: Column flag1 could not be found in the table/view identified with the correlation name S.&lt;/P&gt;&lt;P&gt;ERROR: Expression using equals (=) has components that are of different data types.&lt;/P&gt;&lt;P&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;&lt;P&gt;488 ! /* adapt it to your needs */&lt;/P&gt;&lt;P&gt;489 quit;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 19:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/299026#M60386</guid>
      <dc:creator>ZDR</dc:creator>
      <dc:date>2016-09-16T19:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/299032#M60389</link>
      <description>&lt;P&gt;On 3rd step, after log line 479 you got a message:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR: BY variable&lt;STRONG&gt; trans_mo&lt;/STRONG&gt; is not on input data set &lt;STRONG&gt;WORK.TR_SUM&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The last dataset&amp;nbsp;&lt;STRONG&gt;WORK.TR_SUM &lt;/STRONG&gt;is created in the 2nd step - by&amp;nbsp;SQL.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;trans_mo&amp;nbsp;&lt;/STRONG&gt;is the month used to compute &lt;STRONG&gt;temp_trans_date&amp;nbsp;&lt;/STRONG&gt;together with the year.&lt;BR /&gt;This variable was not selected by SQL, but you can add it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do you realy want to ignore the year (&lt;STRONG&gt;trans_yr&lt;/STRONG&gt;) in step 3? That can give you false results.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I think you should change (log line 475) either to:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;BY &lt;STRONG&gt;CH_ID temp_trans_date &amp;nbsp; -&amp;nbsp;&lt;/STRONG&gt; (mainly year and month as day=01 always)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;or to:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;BY &lt;STRONG&gt;CH_ID TRANS_YR TRANS_MO &amp;nbsp; -&amp;nbsp;&lt;/STRONG&gt; (you will need to add &lt;STRONG&gt;trans_yr&lt;/STRONG&gt; too to the SQL )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Check yourself before going on.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 20:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/299032#M60389</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-09-16T20:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/299298#M60434</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This worked! Well, mostly. No more errors in the code, but two things:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;SAS is only flagging the first transaction in the offending month, not all the transactions. So if there are 20 transactions in the month which should be flagged for a particular user, only one of those is being flagged.&lt;/LI&gt;&lt;LI&gt;When I join the flag column back to trans_new, it doesn’t seem to take. Instead of getting 0s and 1s, it gives me only *s, which is what was in the original data.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any modifications to the code to fix this? I appreciate all your help so far.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 14:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/299298#M60434</guid>
      <dc:creator>ZDR</dc:creator>
      <dc:date>2016-09-19T14:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/299324#M60437</link>
      <description>&lt;P&gt;To help you I need an example of lines &amp;nbsp;where the flags differ form expected, your expected flags on each line and&lt;/P&gt;&lt;P&gt;some explanation.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 15:45:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/299324#M60437</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-09-19T15:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: Summing by 2 other variables as part of a formula</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/299567#M60457</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tweaked it some and reformulated it, and it worked. Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 14:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-by-2-other-variables-as-part-of-a-formula/m-p/299567#M60457</guid>
      <dc:creator>ZDR</dc:creator>
      <dc:date>2016-09-20T14:51:22Z</dc:date>
    </item>
  </channel>
</rss>

