嵌套在SAS中的...循环

时间:2012-11-16 03:05:03

标签: sas

我是SAS的新手,在sql中有最新的代码,我已经停留了一段时间在SAS平台上进行转换。我也尝试在SAS中使用do..while循环,但它不起作用。

for c in (select * from risk.mv_closed_deals d) loop    
  for DatesToInsert in (select distinct(T1.ACTUAL_DATE) as ACTUAL_DATE from VINTAGE_MTD T1 where T1.Actual_Date>c.closed_date) loop
     insert into VINTAGE_MTD (dealdate, actual_date, deal_month, mob, dealno, balance, loanamount, overduedays, status, server)
     values (c.issue_date, DatesToInsert.Actual_Date, to_char(c.issue_date,'yyyy/mm'),
     (to_char(DatesToInsert.actual_date,'yyyy')-to_char(c.issue_date,'yyyy'))*12 + to_char(DatesToInsert.actual_date,'mm') - to_char(c.issue_date,'mm') - 1,
     c.dealno, 0, c.loanamount, 0, 0, 'B2');
  end loop; 
end loop;

1 个答案:

答案 0 :(得分:1)

我会尝试这样的事情:

proc sql;

create table vintage_mdt_new as
select c.issue_date as dealdate
      ,DatesToInsert.Actual_Date as actual_date
      ,put(c.issue_date, yymms.) as deal_month
      ,intck('month', DatesToInsert.actual_date, c.issue_date) as mob
      ,c.dealno as dealno
      ,0 as balance
      ,c.loanamount as loanamount
      ,0 as overduedays
      ,0 as status
      ,'B2' as server
from (select * from risk.mv_closed_deals) as c
     ,(select distinct(T1.ACTUAL_DATE) as ACTUAL_DATE 
       from VINTAGE_MTD T1) as DatesToInsert
where DatesToInsert.Actual_Date > c.closed_date;

quit;

proc append base=VINTAGE_MTD data=vintage_mdt_new;

没试过,所以我不确定是否会奏效。