sas数字转日期格式 |
您所在的位置:网站首页 › sas时间转换 › sas数字转日期格式 |
(转) 在SAS处理中,特别是在多个数据集合并过程中,我们经常要遇到 日期格式不匹配的情况,但是 日期 又是一个非常关键的 匹配关键词,所以有必要 将各种不同的 日期变量的 转化 方法在这里做一个总结,不周到之处请广大博友提出修改意见。 1. input: 年月日 output: 年月 ,这里要区分 显示 和 实际值 的区别。 输入的时候,有时是数值型,我们可能要将其 转化为字符型,然后再定义其 日期的显示格式; 比较常用的命令: 数值格式转化为字符型: put(year(date),z4.0) ||'-'|| put(month(date),z2.0); 字符格式转化为日期型:input(date,yymmdd10.) Formats: DATEw. date9. 01JAN2014 DDMMYYw. YYMMDDw. YYMMDD10. 2014-06-18 YYMMxw. YYMONw. put x yymon7.; 2012JAN Functions: DAY MONTH MDY date=mdy(1,2,2001); 2001-01-02 YEAR 季度:QTR(DATE) 今天日期返回函数:TODAY() data test; input time yymmn6.; date=time-1; format date yymmd7. time yymmd7.; cards; 201201 201202 201203 201204 201205 ; run; Data RiskFreeRateByMonth; SetRiskFreeRateByMonth; year_month=put(year(date),z4.0) ||'-'|| put(month(date),z2.0); Proc print data=_last_(obs=25); Run; We can also use the “YYMMD.” format to do the same thing For example: year_month=put(date,YYMMD.); data data _null_; x='7jan2012'd; put x yymm7.; put x yymmc7.; put x yymmd7.; put x yymmn6.; put x yymmp7.; put x yymms7.; put x yymon7.; run; < |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |