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