简体   繁体   English

PROC SQL SAS 编程

[英]PROC SQL SAS PROGRAMMING

I have the following dataset:我有以下数据集:

Name  Address         Bank_Account  Ph_NO    IP_Address   Chargeoff
AJ    12 ABC Street     1234        369      12.12.34         0
CK    12 ABC Street     1234        450      12.12.34         1
DN    15 JMP Street     3431        569      13.8.09          1
MO    39 link street    8421        450      05.67.89         1
LN    12 ABC Street     1234        340      14.75.06         1
ST    15 JMP Street     8421        569      13.8.09          0`

Using this dataset I want to create the below view in SAS:使用此数据集,我想在 SAS 中创建以下视图:

 Name   CountOFAddr CountBankacct CountofPhone CountOfIP CountCharegeoff
  AJ       3             3           1            2             2
  CK       3             3           2            2             3
  DN       2             1           2            2             1
  MO       1             2           2            1             2
  LN       3             3           1            1             2
  ST       2             2           2            2             2

The output variables indicates as follows :输出变量表示如下:

-CountOfAddr : For AJ countOFAddr is 3 which means that AJ Shares its address with itself, CK and LN -CountOfAddr : 对于 AJ,countOFAddr 是 3,这意味着 AJ 与自己,CK 和 LN 共享其地址

-CountBankAcct : For MO count of BankAcct is 2 which means that MO Shares its bank account number with itself and ST.Similarly for variables CountofPhone and CountOfIP. -CountBankAcct :对于 BankAcct 的 MO 计数为 2,这意味着 MO 与其自身和 ST 共享其银行帐号。对于变量 CountofPhone 和 CountOfIP 也是如此。

-CountChargeoff: This one is a little tricky it basically implies that AJ is Linked to CK And LN through address...and both CK and LN have been charged off so the countChargeoff for AJ is 2. -CountChargeoff:这个有点棘手,它基本上意味着 AJ 通过地址链接到 CK 和 LN……并且 CK 和 LN 都已被扣费,因此 AJ 的 countChargeoff 为 2。

For CK the countChargeOff is 3 because it is linked with itself, MO through Bank Account, and LN/AJ through street address...so total chargeoff in CK's Network is 3 (CO count of AJ+CO count of CK+CO Count of MO+CO count of LN )对于CKcountChargeOff3 ,因为它与自己联系, MO通过银行账户和LN/AJ通过街道地址...所以总chargeoffCK's网络是3的(CO计数AJ+CO的计数CK+CO计数的LN MO+CO计数 )

I currently work as a Risk Analyst in a Financial Service Firm and the code for this problem may help us to significantly reduce funding of fraudulent accounts.我目前在一家金融服务公司担任风险分析师,这个问题的代码可以帮助我们显着减少欺诈账户的资金。

Thanks.谢谢。

SQL Fiddle Demo SQL 小提琴演示

SELECT 
    Name,
    (SELECT Count(Address)
     FROM dataset d2
     WHERE d1.Address = d2.Address 
    ) CountOFAddr,

    (SELECT Count(Bank_Account)
     FROM dataset d2
     WHERE d1.Bank_Account = d2.Bank_Account
    ) CountBankacct,

    (SELECT Count(Ph_NO)
     FROM dataset d2
     WHERE d1.Ph_NO = d2.Ph_NO
    ) CountofPhone,

    (SELECT Count(IP_Address)
     FROM dataset d2
     WHERE d1.IP_Address = d2.IP_Address
    ) CountOfIP, 

    (SELECT count(d2.Chargeoff) 
     FROM dataset d2
     WHERE  d1.name <> d2.name
       and (   d1.Address = d2.Address
            or d1.Bank_Account = d2.Bank_Account
            or d1.Ph_NO = d2.Ph_NO 
            or d1.IP_Address = d2.IP_Address
           )
    ) CountCharegeoff           
FROM dataset d1

I Include the charge off calculation. I 包括冲销计算。

Bring all d2 <> d1.name where have any field in common.将所有d2 <> d1.name放在有任何共同字段的地方。 Then count that.那就这样算吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM