SAS 日期处理(一)

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
目录

点击跳转函数跳转使用例子
tod.时间补全函数
anydtdtm.缺失日期读入函数
anydtdte.缺失自动填补最早日期

1.日期格式


2.缺失日期的比较

anydtdtm.函数

data b;
	a1 = "2011-01-15T12:55:00";  **完整e8601格式,可以识别;
	a2 = input(a1,anydtdtm.);

	b1 = "2011-01-15";    /*只有日期,可以识别*/
	b2 = input(b1,anydtdtm.);

	c1 = "2011-01";  
	c2 = input(c1,anydtdtm.); /*只有年月,可以识别*/

	d1 = "2011";
	d2 = input(d1,anydtdtm.);  /*只有年份无法读入,使用 anydtdte. 自动补齐最早日期后再读入*/

	e1 = "2011-01-15T12:55"; /*时间格式不完整,无法读入,使用tod.函数或time8.函数进行补0变为标准时间*/
	e2 = input(e1,anydtdtm.);

	f1 = "2011/01/15";   /*日期之间是斜杆,也可以识别*/
	f2 = input(f1,anydtdtm.);

	g1 = "2011-01-15 12:55:00";  /*时间日期没有T可以识别*/
	g2 = input(g1,anydtdtm.);
run;

tod. 时间不完整填补

tod.函数
转换时间一般用的 time8. 但是HH小于10,前面不会补0,用tod8. 可以补齐前后的0

data t;
	input tim $;
cards;
2:22
12:12:55
21:13
2:13
;
run;

data t2;
	set t;
	tim2=input(tim,time8.);
	format tim2 time8.;
run;

data t3;
	set t2;
	tim3_Tod=put(tim2,tod8.);  **用tod8.函数;
	tim4_Time=put(tim2,time8.);
run;

image


缺失自动填补最早日期

anydtdte.函数

data test;
    a="2021-08";
    b=input(a,anydtdte.);
    format b yymmdd10.;
run;
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6