如何将 SAS 日期(例如
"30JUL2009"d
)转换为 YYYYMMDD
格式(例如 20090730)?
举个例子:
data _null_;
format test ?????;
test=today();
put test=;
run;
会在日志中给我“test=20090730”...
data _null_;
format test yymmddn8.;
test=today();
put test=;
run;
%let expectdate1=%sysfunc(putn(%eval(%sysfunc(today())-1),yymmddn8.));
您想使用 yymmddn8 格式。 “n”表示无分隔符。
根据 http://support.sas.com/kb/24/610.html,您可以指定 B 表示空白、C 表示冒号、D 表示破折号、N 表示无分隔符、P 表示句点或 S 表示斜杠。
这个也可以解决问题
%let today=%sysfunc(today(),yymmddn8.);
%put &today.;
以下链接中的所有内容
这是我在宏中的做法,但肯定有一个格式???!!!
%let today=%sysfunc(compress(%sysfunc(today(),yymmddd10.),'-'));
很奇怪 - INFORMAT yymmdd8。给出 YYYYMMDD 结果,而 FORMAT yymmdd8.给出 YY-MM-DD 结果!!
当您在“索引”选项卡中输入“日期”,然后选择“日期和时间格式”时,您可以在“帮助”选项卡中看到所有日期和时间格式
%let t=%sysfunc(today(),yymmddn8.); %放 &t.;