BookmarkSubscribeRSS Feed
KMWWN156
Fluorite | Level 6

I am looking to transpose account level date which currently has one row per entry, with upto 5 rows per account as i am interested in the last 5 payments for an account, some accounts have less than 5 payments.

 

I want to transpose this so each account has one row, with the payment data across multiple columns.

 

Data is currently like this.

AccnoTranDateTranAmtTranCode
Account121Jul202675.2653
Account224Dec202126.8653
Account316May201440.0053
Account316Jan201540.0053
Account316Sep201540.0053
Account316Oct201540.0053
Account403Mar202320.0053
Account502Nov20201.0053
Account502Dec20201.0053
Account531Dec20201.0053
Account502Feb20211.0053
Account502Mar20211.0053

 

And i want it to appear like this.

AccnoTranDate1TranAmt1TranCode1TranDate2TranAmt2TranCode2TranDate3TranAmt3TranCode3TranDate4TranAmt4TranCode4TranDate5TranAmt5TranCode5
Account121Jul202675.2653            
Account224Dec202126.8653            
Account316May201440.005316Jan201540.005316Sep201540.005316Oct201540.0053   
Account403Mar202320.0053            
Account502Nov20201.005302Dec20201.005331Dec20201.005302Feb20211.005302Mar20211.0053

 

Thanks,

6 REPLIES 6
KMWWN156
Fluorite | Level 6
It is being provided to a stakeholder alongside other account information, and the payment data has been asked for in the requested format above. Thanks
PaigeMiller
Diamond | Level 26

You can use PROC TRANSPOSE as in this example: 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n01rzqgzs8vq1bn10h1wtx914kyf.htm

 

If you want actual code, you will need to provide data in a usable form, as seen in these examples and instructions.

 

PS: I understand that a key person wants the data in this form; but please understand that is the only reason to do this. If you are programming for yourself, and want to use the results in further analyses, tables or plots, you would never do this transpose. As stated by @Kurt_Bremser , this transposed arrangement of the data makes all other programming much more difficult.

--
Paige Miller
data_null__
Jade | Level 19

You need a variable to make the transactions unique within the accno.

 

data test;
   infile cards dsd dlm='09'x firstobs=2;
   input Accno $ TranDate:date9. TranAmt TranCode;
   format trandate date11.;
   datalines;
Accno	TranDate	TranAmt	TranCode
Account1	21-Jul-26	75.26	53
Account2	24-Dec-21	26.86	53
Account3	16-May-14	40	53
Account3	16-Jan-15	40	53
Account3	16-Sep-15	40	53
Account3	16-Oct-15	40	53
Account4	3-Mar-23	20	53
Account5	2-Nov-20	1	53
Account5	2-Dec-20	1	53
Account5	31-Dec-20	1	53
Account5	2-Feb-21	1	53
Account5	2-Mar-21	1	53
;;;;
   run;
data test;
   set test;
   by accno;
   if first.accno then ndx = 0;
   ndx + 1;
proc print;
   run;
proc transpose data=test out=tall name=vname;
   by accno ndx;
   var tran:;
   run;
proc print;
   run;
proc transpose data=tall out=wide(drop=_name_);
   by accno;
   var col1;
   id vname ndx;
   format trandate: date11.;
   run;
proc print;
   run;

Screenshot 2026-08-04 101917.png

Ksharp
Super User

The most simple way is using PROC SUMMARY.

 

data test;
   infile cards truncover expandtabs;
   input Accno $ TranDate:date9. TranAmt TranCode;
   format trandate date11.;
   datalines;
Account1	21-Jul-26	75.26	53
Account2	24-Dec-21	26.86	53
Account3	16-May-14	40	53
Account3	16-Jan-15	40	53
Account3	16-Sep-15	40	53
Account3	16-Oct-15	40	53
Account4	3-Mar-23	20	53
Account5	2-Nov-20	1	53
Account5	2-Dec-20	1	53
Account5	31-Dec-20	1	53
Account5	2-Feb-21	1	53
Account5	2-Mar-21	1	53
;;;;
proc sql noprint;
select max(n) into :n from
(select count(*) as n from test group by Accno);
quit;
proc summary data=test;
by Accno;
output out=want idgroup(out[&n] (TranDate TranAmt TranCode)=);
run;

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 127 views
  • 1 like
  • 5 in conversation