<?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: Grouping Transaction Data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389057#M93290</link>
    <description>&lt;P&gt;I think this does what you want except I believe acoount S1 tran_code 52 in your output is incorrect as it's earlier tran_group is "Living Expense:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
infile datalines dlm=',' truncover;
informat account $2. date DATE9. tran_code $2. desc $20. tran_group $20.;
input account date tran_code desc tran_group;
format date DATE9.;
datalines;
S1, 12MAY2010, 47, From KPMG, Income
S1, 10SEP2010, 52, Expense PPWC, Living Expense
S1, 16APR2011, 47, From KPMG,
S1, 14JUN2011, 52, From KPMG,
T1, 11MAR2014, 30, From Forts Mining, Income
T1, 11MAY2014, 30, From Forts Mining,
T1, 12SEP2017, 41, From ABA Accountants, Income
T1, 10JUN2018, 31, From ATO XYX, Tax Expense
U1, 14FEB2011, 32, From YYY Surveyors, Income
U1, 20MAY2011, 41, From ATA LAWYERS XYX, Income,
U1, 14JUN2011, 32, From YYY Surveyors,
U1, 16OCT2011, 32, From ATA LAWYERS XYX,
U1, 18DEC2011, 41, From ATA LAWYERS XYX,
;
run;



proc sql;
	create table income
	as select *
	from temp
	where  tran_group="Income";
quit;

proc sql;
	update temp a
	set tran_group = 
	(select "Income Non Base" as tran_group
	from income b
	where b.account=a.account
		and b.tran_code = a.tran_code
		and b.date &amp;lt; a.date)
	where a.tran_group=""
	;
quit;
	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Aug 2017 08:10:50 GMT</pubDate>
    <dc:creator>ChrisBrooks</dc:creator>
    <dc:date>2017-08-18T08:10:50Z</dc:date>
    <item>
      <title>Grouping Transaction Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389052#M93289</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to identify account transactions that have a blank transaction group (tran_group = ' ')&lt;BR /&gt;AND have a description (desc) the same as a description from a previous transaction that has been already&lt;BR /&gt;been classified as 'Income' (tran_group = Income).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The background is that a transaction would be classified as 'Income' if it meets certain criteria -&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;ie regular and amount within 10% of last payment.&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;However some transactions will be missed such as bonuses and commissions.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So I would like to identify these and classify them as tran_group = 'Income Non Base'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To do this I need the sas code to look back through all the accounts transactions&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;- which could be most likely upto 100 transactions prior to the current transaction and check if the same 'desc' has appeared before AND has also previously been flagged as 'Income'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;(tran_group = 'Income'), otherwise left blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a temp dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data temp;&lt;BR /&gt;infile datalines dlm=',' truncover;&lt;BR /&gt;informat account $2. date DATE9. tran_code $2. desc $20. tran_group $20.;&lt;BR /&gt;input account date tran_code desc tran_group;&lt;BR /&gt;format date DATE9.;&lt;BR /&gt;datalines;&lt;BR /&gt;S1, 12MAY2010, 47, From KPMG, Income&lt;BR /&gt;S1, 10SEP2010, 52, Expense PPWC, Living Expense&lt;BR /&gt;S1, 16APR2011, 47, From KPMG,&lt;BR /&gt;S1, 14JUN2011, 52, From KPMG,&lt;BR /&gt;T1, 11MAR2014, 30, From Forts Mining, Income&lt;BR /&gt;T1, 11MAY2014, 30, From Forts Mining,&lt;BR /&gt;T1, 12SEP2017, 41, From ABA Accountants, Income&lt;BR /&gt;T1, 10JUN2018, 31, From ATO XYX, Tax Expense&lt;BR /&gt;U1, 14FEB2011, 32, From YYY Surveyors, Income&lt;BR /&gt;U1, 20MAY2011, 41, From ATA LAWYERS XYX, Income,&lt;BR /&gt;U1, 14JUN2011, 32, From YYY Surveyors,&lt;BR /&gt;U1, 16OCT2011, 32, From ATA LAWYERS XYX,&lt;BR /&gt;U1, 18DEC2011, 41, From ATA LAWYERS XYX,&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When this match occurs I would like the current transaction to be classified as 'Income Non Base' (tran_group = 'Income Non Base')&lt;/P&gt;&lt;P&gt;So in the infile example above, the following transactions in bold would then be classified as 'Income Non Base'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;S1, 12MAY2010, 47, From KPMG, Income&lt;BR /&gt;S1, 10SEP2010, 52, Expense PPWC, Living Expense&lt;BR /&gt;&lt;STRONG&gt;S1, 16APR2011, 47, From KPMG, Income Non Base&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;S1, 14JUN2011, 52, From KPMG, Income Non Base&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;T1, 11MAR2014, 30, From Forts Mining, Income&lt;BR /&gt;&lt;STRONG&gt;T1, 11MAY2014, 30, From Forts Mining, Income Non Base&lt;/STRONG&gt;&lt;BR /&gt;T1, 12SEP2017, 41, From ABA Accountants, Income&lt;BR /&gt;T1, 10JUN2018, 31, From ATO XYX, Tax Expense&lt;/P&gt;&lt;P&gt;U1, 14FEB2011, 32, From YYY Surveyors, Income&lt;BR /&gt;U1, 20MAY2011, 41, From ATA LAWYERS XYX, Income,&lt;BR /&gt;&lt;STRONG&gt;U1, 14JUN2011, 32, From YYY Surveyors, Income Non Base&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;U1, 16OCT2011, 32, From ATA LAWYERS XYX, Income Non Base&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;U1, 18DEC2011, 41, From ATA LAWYERS XYX, Income Non Base&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Sally&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 07:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389052#M93289</guid>
      <dc:creator>Selli5</dc:creator>
      <dc:date>2017-08-18T07:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping Transaction Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389057#M93290</link>
      <description>&lt;P&gt;I think this does what you want except I believe acoount S1 tran_code 52 in your output is incorrect as it's earlier tran_group is "Living Expense:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
infile datalines dlm=',' truncover;
informat account $2. date DATE9. tran_code $2. desc $20. tran_group $20.;
input account date tran_code desc tran_group;
format date DATE9.;
datalines;
S1, 12MAY2010, 47, From KPMG, Income
S1, 10SEP2010, 52, Expense PPWC, Living Expense
S1, 16APR2011, 47, From KPMG,
S1, 14JUN2011, 52, From KPMG,
T1, 11MAR2014, 30, From Forts Mining, Income
T1, 11MAY2014, 30, From Forts Mining,
T1, 12SEP2017, 41, From ABA Accountants, Income
T1, 10JUN2018, 31, From ATO XYX, Tax Expense
U1, 14FEB2011, 32, From YYY Surveyors, Income
U1, 20MAY2011, 41, From ATA LAWYERS XYX, Income,
U1, 14JUN2011, 32, From YYY Surveyors,
U1, 16OCT2011, 32, From ATA LAWYERS XYX,
U1, 18DEC2011, 41, From ATA LAWYERS XYX,
;
run;



proc sql;
	create table income
	as select *
	from temp
	where  tran_group="Income";
quit;

proc sql;
	update temp a
	set tran_group = 
	(select "Income Non Base" as tran_group
	from income b
	where b.account=a.account
		and b.tran_code = a.tran_code
		and b.date &amp;lt; a.date)
	where a.tran_group=""
	;
quit;
	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 08:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389057#M93290</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-08-18T08:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping Transaction Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389063#M93292</link>
      <description>&lt;P&gt;Next code was tested and results as desired:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
infile datalines dlm=',' truncover;
informat account $2. date DATE9. tran_code $2. desc $20. tran_group $20.;
input account date tran_code desc tran_group;
format date DATE9.;
datalines;
S1, 12MAY2010, 47, From KPMG, Income
S1, 10SEP2010, 52, Expense PPWC, Living Expense
S1, 16APR2011, 47, From KPMG,
S1, 14JUN2011, 52, From KPMG,
T1, 11MAR2014, 30, From Forts Mining, Income
T1, 11MAY2014, 30, From Forts Mining,
T1, 12SEP2017, 41, From ABA Accountants, Income
T1, 10JUN2018, 31, From ATO XYX, Tax Expense
U1, 14FEB2011, 32, From YYY Surveyors, Income
U1, 20MAY2011, 41, From ATA LAWYERS XYX, Income,
U1, 14JUN2011, 32, From YYY Surveyors,
U1, 16OCT2011, 32, From ATA LAWYERS XYX,
U1, 18DEC2011, 41, From ATA LAWYERS XYX,
;
run;

data temp1 temp2;
 set temp;
     if tran_group = ' ' then output temp2;
     else output temp1;
run;

proc sql;
  create table temp3
  as select distinct a.account, a.date, a.tran_code, a.desc,
     'Income Non Base' as tran_group
  from temp2 as a 
  left join
       temp1 as b
     on a.account = b.account and
        a.date ge b.date and
        a.desc = b.desc;
quit;  

data want; set temp1 temp3; run;
proc sort data=want;
  by account date;
run;




 
 
 
 
 
   &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Aug 2017 08:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389063#M93292</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-18T08:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping Transaction Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389072#M93293</link>
      <description>&lt;P&gt;Thanks This works on this temp datset, but when I try running it on the real data I get this error message?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'Salary' is a variable the same as 'desc' in the temp dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Sally&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV class="sasSource"&gt;OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;61&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;62 proc sql;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;63 update tran_group_sorted a&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;64 set tran_group =(select "Income Non Base" as tran_group&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;65 from income b&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;66 where b.account=a.account and b.salary = a.salary and b.date &amp;lt; a.date)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;67 where a.tran_group = " "&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;68 ;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;STRONG&gt;ERROR: Subquery evaluated to more than one row.&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Correlation values are: account='100050S7' salary='DIRECT CREDIT From: CTRLINK PENSION Ref' date=20761 .&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;69 quit;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;real time 1.32 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;cpu time 0.55 seconds&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="sasSource"&gt;70&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;71 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;84&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 18 Aug 2017 09:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389072#M93293</guid>
      <dc:creator>Selli5</dc:creator>
      <dc:date>2017-08-18T09:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping Transaction Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389075#M93294</link>
      <description>&lt;P&gt;The subquery produces more than one result for a given where condition. You probably need to refine the b.date &amp;lt; a.date part so that it yields only the maximum date within that range.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 10:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/389075#M93294</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-18T10:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: PRXMATCH</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/393086#M94647</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to identify credit card numbers &amp;nbsp;= 16 digits within a text string 'desc'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the following code which is identifying numbers equal to 16 digits, but it also idenitfing numbers greater than&amp;nbsp;16 digits.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prxmatch('/\d{16}/',desc) &amp;gt; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I identify numbers exactly&amp;nbsp;16 digits long?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Sally&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 02:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-Transaction-Data/m-p/393086#M94647</guid>
      <dc:creator>Selli5</dc:creator>
      <dc:date>2017-09-05T02:01:06Z</dc:date>
    </item>
  </channel>
</rss>

