data have;
infile cards expandtabs;
input cust_id account prod $ limit : comma. balance : comma.;
cards;
111 1234 A 10,000 500
111 5678 B 20,000 1,000
111 2345 C 3,000 2,000
111 6789 B 2,000 3,000
222 4321 A 1,000 2,000
222 8765 A 4,000 1,000
222 7654 C 6,000 5,000
;
proc sort data=have out=temp1;by cust_id descending limit;run;
data temp11;
set temp1;
by cust_id descending limit;
if first.cust_id then n=0;
if first.limit then n+1;
if n=1;
run;
data part1;
do until(last.cust_id);
set temp11;
by cust_id;
length prod_max_lmt $ 200;
prod_max_lmt=catx('&',prod_max_lmt,prod);
end;
keep cust_id prod_max_lmt limit;
rename limit=max_lmt;
run;
proc sort data=have out=temp2;by cust_id balance;run;
data temp21;
set temp2;
by cust_id balance ;
if first.cust_id then n=0;
if first.balance then n+1;
if n=1;
run;
data part2;
do until(last.cust_id);
set temp21;
by cust_id;
length prod_min_bal $ 200;
prod_min_bal=catx('&',prod_min_bal,prod);
end;
keep cust_id prod_min_bal balance;
rename balance=min_bal;
run;
data want;
merge part1 part2;
by cust_id;
run;
... View more