SAS infile 導入txt示例


概要說明:

以下代碼包含的知識點:

1)ods

2)format picture

3)symputx


ods pdf file="D:\fgroup\users\output\time.pdf"/*startpage=no*/;
libname data_u "D:\fgroup\users\data";



**定義日期輸出格式,這個函數很重要,可以自由定義時間的輸出格式,要好好理解;
proc format;
   picture mydate
      low-high='%Y/%0m/%0d %0H:%0M:%0S'(datatype=datetime);
run;


/*
* 導入用戶填寫時間表;
*/

data data_u.user    ;
    %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
    infile 'D:\fgroup\users\source\user-2016-11-29.txt' delimiter = ',' MISSOVER DSD  firstobs=2 ;
    
    informat UserId $40. ;
    informat AddTime anydtdtm40. ;

     format UserId $40. ;
     format AddTime datetime.;

    input
    UserId $
    AddTime
    ;

    
    if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
    
run;


/*增加兩列日期和指定格式的時間列,測試在類型轉換執行效率問題*/
data data_u.user;
    set data_u.user;
    adddate=datepart(AddTime);
    t_addtime=AddTime;
    format t_addtime mydate19.;
    d_year=year(adddate);
    d_month=month(adddate);
run;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM