SELECT语句SAS中的INTCK函数

时间:2012-05-13 02:14:28

标签: sas

我很难获得INTCK函数来返回我使用以下查询的结果

proc sql;
CREATE TABLE SASAVE.WEEK_NUM AS
SELECT DISTINCT MUC.CODE
        ,MUC.LOB
        ,MMD.MAX_DATE
        ,MMD.MIN_DATE
        ,INTCK('WEEK', MMD.MAX_DATE, MMD.MIN_DATE) AS WEEK_COUNT
FROM    SASAVE.MUC,
        MMD             
WHERE MMD.LOB = MUC.LOB
AND MMD.CODE = MUC.CODE
quit;

这是MUC和MMD表中的数据

 **MMD**
    MIN_DATE         MAX_DATE       CODE    LOB
    13FEB2012   11MAY2012   527A    TMZ
    13FEB2012   1MAY2012    TB50    ZAE
    13FEB2012   10MAY2012   3O05    ZAA

**MUC**
CODE      LOB
527A    TMZ
TB50    ZAE
3O05    ZAA

如果我能使用INTCK功能获得周数,请告诉我

感谢

1 个答案:

答案 0 :(得分:2)

好像你差不多......这很有效。

Data mmd;
 input min_date:DATE9. max_date:date9. code $ lob $;
 format min_date max_date mmddyy10.;
 datalines;
13FEB2012   11MAY2012   527A    TMZ
13FEB2012   01MAY2012    TB50    ZAE
13FEB2012   10MAY2012   3O05    ZAA
;

Data muc;
 input code $ lob $;
 datalines;
527A    TMZ
TB50    ZAE
3O05    ZAA
;

proc sql;
 CREATE TABLE WEEK_NUM AS
 SELECT DISTINCT MUC.CODE
  ,MUC.LOB
  ,MMD.MAX_DATE
  ,MMD.MIN_DATE
  ,INTCK('WEEK', MMD.MIN_DATE, MMD.MAX_DATE) AS WEEK_COUNT
 FROM MUC, MMD             
 WHERE MMD.LOB = MUC.LOB
  AND MMD.CODE = MUC.CODE;
quit;