BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

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?

Ronein_0-1659508920806.png

 

 


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)*/

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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) 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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) 
Ronein
Onyx | Level 15
One question please:
What is the reason to use " call missing(con_Degem_amount);" ?

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 689 views
  • 2 likes
  • 2 in conversation