sas 日期 - 将 Today() 转换为 yyyymmdd 格式

问题描述 投票:0回答:6

如何将 SAS 日期(例如

"30JUL2009"d
)转换为
YYYYMMDD
格式(例如 20090730)?

举个例子:

data _null_;
  format test ?????;
  test=today();
  put test=;
run;

会在日志中给我“test=20090730”...

date format sas
6个回答
26
投票
data _null_;
    format test yymmddn8.;
    test=today();
    put test=;
run;

YYMMDDxw。文档


14
投票
%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 表示斜杠。


3
投票

这个也可以解决问题

%let today=%sysfunc(today(),yymmddn8.);
%put &today.;

以下链接中的所有内容

https://communities.sas.com/thread/60111


2
投票

这是我在宏中的做法,但肯定有一个格式???!!!

%let today=%sysfunc(compress(%sysfunc(today(),yymmddd10.),'-'));

很奇怪 - INFORMAT yymmdd8。给出 YYYYMMDD 结果,而 FORMAT yymmdd8.给出 YY-MM-DD 结果!!


0
投票

当您在“索引”选项卡中输入“日期”,然后选择“日期和时间格式”时,您可以在“帮助”选项卡中看到所有日期和时间格式


0
投票

%let t=%sysfunc(today(),yymmddn8.); %放 &t.;

© www.soinside.com 2019 - 2024. All rights reserved.