2014-11-25 59 views
3

在嘗試啓動並運行DS2線程時出現奇怪的錯誤代碼。SAS proc ds2 YEAR功能

proc ds2; 
    thread work.th_ieb /overwrite=yes; 
    dcl DOUBLE Beg_Jahr; 
    METHOD RUN(); 
    set {select id, date 
     from DATA 
     }; 
    IF FIRST.id THEN DO; 
    Beg_Jahr = YEAR(DATE); 
    OUTPUT; 
    END; 
END; 
endthread; 
run; 

的錯誤是:

ERROR: Compilation error. 
ERROR: Illegal conversion for date or time type. Source line 34. 

它工作正常,沒有YEAR的功能。有任何想法嗎?

+0

請確保與您稱爲'date'的變量關聯的類型實際上具有日期類型。在'PROC DS2'中,實際上有一個日期數據類型,與「傳統」SAS不同,日期存儲爲自1960年1月1日以來的天數。 – 2014-11-26 15:20:46

+0

即使添加'dcl DATE date',它也不會運行。 – user3614882 2014-11-27 16:09:53

回答

0

我坦率地承認,我並不完全理解DS2的所有錯綜複雜的問題,但是這個解決方案對我很有用。

將名爲date的變量的名稱更改爲其他內容,因爲date是DS2中的關鍵字。關於這些事情,DS2比基礎SAS更挑剔。這裏我僅僅爲了舉例而稱之爲變量birthdt

確保輸入數據集中的日期變量是數字。

proc ds2; 
    thread work.th_ieb/overwrite = yes; 
     dcl double beg_jahr; 
     method run(); 
      set { 
       select id, birthdt 
       from data 
      }; 
      if first.id then do; 
       beg_jahr = year(birthdt); 
       output; 
      end; 
     end; 
    endthread; 
run; 
quit; 
1

這裏是一個完整的示例程序,我用來重現您的問題,這個版本在我的網站工作。一個關鍵的變化是在sas源數據中使用11.0而不是date9的'dt'格式。即使SAS文檔聲明應該,我也無法使用date9工作。

data stuff; 
    format dt 11.0 id 11.0; 
    dt='01JAN2015'd; 
    id = 1; 
run; 

proc ds2; 
    thread work.th_ieb /overwrite=yes; 
     dcl double Beg_Jahr; 
     dcl date ds2_dt having format yymmdd10.; 

     METHOD RUN(); 
      set {select id, dt 
       from stuff 
       order by id 
       }; 
      by id; 

      ds2_dt = to_date(dt); 
      put ds2_dt=; 

      IF FIRST.id THEN DO; 
       Beg_Jahr = year(dt); 
       put beg_jahr=; 
       OUTPUT; 
      END; 
     END; 
    endthread; 

    data; 
     dcl thread th_ieb t_inst; 

     method run(); 
      set from t_inst threads=2; 
     end; 
    enddata; 
run;