2016-03-02 128 views
0

我導入了一個cvs文件,並在我的sas文件中包含一個由四位數字組成的變量「出發時間」,例如,上午08時56分爲0856。我希望SAS能夠將其識別爲時間,並希望其顯示爲08:56。我曾嘗試過:將數值變量轉換爲SAS時間變量

put DEP_TIME hhmm5.; 

format DEP_TIME hhmm5.; 

不起作用。似乎無法弄清楚這一點。

任何線索?

+0

回去並在您的CSV導入中修復此問題 - 儘可能將信息和格式添加到變量中。 – Reeza

回答

0

我不認爲有一個信息會將4位數的字符串轉換爲時間。

有幾個方法可以做到這一點,無論使用hms()substr()功能,或自定義圖片格式:

 
proc format ;             
    picture TM 
    low-high = '00:00' ;         
run ; 

data want ; 
    set have ; 
    /* hms and substr method */ 
    new_time1 = hms(substr(dep_time,1,2),substr(dep_time,3,2)) ; 
    format new_time1 hhmm5. ; 

    /* input/put with picture format */ 
    new_time2 = input(put(input(dep_time,4.),tm.),time5.) ; 
    format new_time2 hhmm5. ; 
run ; 
+0

substr像一個魅力工作!非常感謝! – Ije

2

了信息B8601TM。

33   data _null_; 
34   t='0856'; 
35   time = input(t,B8601TM.); 
36   format time time.; 
37   put 'NOTE: ' (_all_)(=); 
38   run; 

NOTE: t=0856 time=8:56:00