Hello
I have a data set with loans information.
Each customer can appear in multiple rows (If he took multiple loans)..
I want to create a summary table that each customerID will appear in 1 row per month (YYMM).
In the wanted data set will have 3 columns:
ID
month
Concatenate_Type_Amount
What is the way to create this data set please?
Data Loans;
input ID Type amount month;
cards;
11111 712 1000 2201
11111 987 2000 2201
11111 712 3000 2201
11111 712 5000 2202
22222 712 4300 2201
22222 987 1500 2201
;
Run;
The wanted data set will have 3 rows:
/*Wanted table*/
/*11111 2201 (712-4000),(987-2000)*/
/*11111 2202 (712-5000)*/
/*22222 2201 (712-4300),(987-1500)*/
Try this
Data Loans;
input ID Type amount month;
cards;
11111 712 1000 2201
11111 987 2000 2201
11111 712 3000 2201
11111 712 5000 2202
22222 712 4300 2201
22222 987 1500 2201
;
Run;
proc summary data = Loans nway;
class ID month type;
var amount;
output out = temp(drop = _:) sum=;
run;
data want(drop = type amount);
set temp;
by ID month;
length con_type_amount $200;
con_type_amount = catx(',', con_type_amount, cats('(', type, '-', amount, ')'));
if last.month then do;
output;
call missing(con_type_amount);
end;
retain con_type_amount;
run;
Result:
ID month con_type_amount 11111 2201 (712-4000),(987-2000) 11111 2202 (712-5000) 22222 2201 (712-4300),(987-1500)
Try this
Data Loans;
input ID Type amount month;
cards;
11111 712 1000 2201
11111 987 2000 2201
11111 712 3000 2201
11111 712 5000 2202
22222 712 4300 2201
22222 987 1500 2201
;
Run;
proc summary data = Loans nway;
class ID month type;
var amount;
output out = temp(drop = _:) sum=;
run;
data want(drop = type amount);
set temp;
by ID month;
length con_type_amount $200;
con_type_amount = catx(',', con_type_amount, cats('(', type, '-', amount, ')'));
if last.month then do;
output;
call missing(con_type_amount);
end;
retain con_type_amount;
run;
Result:
ID month con_type_amount 11111 2201 (712-4000),(987-2000) 11111 2202 (712-5000) 22222 2201 (712-4300),(987-1500)
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.