BookmarkSubscribeRSS Feed
dash
Obsidian | Level 7
how to display housing(H) and vehicle loan(V) of a customer who had taken in the same year?
table is like that
data cust_loan;
input accno loanno $ year loan_amount;
cards;
110010 H023 2006 400000
110126 H024 2006 410000
110278 H045 2006 420000
112345 H046 2007 430000
110345 H056 2007 440000
110023 V001 2006 45000
110126 V002 2006 60000
110126 V002 2007 60000
110345 V052 2007 60400
110127 V512 2007 60078
;

I have got result for cust who had taken both housing and vehicle loan but unable to get the result in the same year. plz check
proc sql;
select * from cust_loan where loanno like 'H%' and accno in (select accno from cust_loan
where loanno like 'V%')
UNION ALL
select * from cust_loan where loanno like 'V%' and accno in(select accno from cust_loan
where loanno like 'H%');
quit;
3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12
you could use the "old" data step approach.

Use your SQL code to get people with both vehicle and home loans. This would get it down to people with multiple loans in one year:

PROC SORT; by year accno loanno; RUN;

DATA MultLoans;
SET;
BY year accno;
IF first.accno & last.accno THEN DELETE;
RUN;

This would have a few false positives (two cars in one year and house in another), but you could use a similar data step to winnow it further.
dash
Obsidian | Level 7
thanks sir, but is it possible to write the same prog in proc sql
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Dash,

This is a possible solution:
[pre]
proc SQL;
create table r as select *
from cust_loan
group by year,accno
having count(*) > 1
order by year,accno
;quit;
[/pre]
Sincerely,
SPR

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 3 replies
  • 1411 views
  • 0 likes
  • 3 in conversation