%PUT-从数字宏变量以格式打印日期和时间

时间:2019-02-27 21:12:03

标签: date sas format

我遇到了这个看起来很简单的问题。

我有这样的宏:

slim

所以基本上相反,%macro test; /* I start from it */ %let time_ = %sysfunc(time()); %let date_ = %sysfunc(date()); %let time1 = %sysfunc(time()); data _null_; timedelay = sleep(5, 1); run; %let time2 = %sysfunc(time()); %let diff = %sysevalf(&time2 - &time1); %put Timenow: &time_; %put DateNOw: &date_; %put TimeDifference: &diff; /*Above works as I want*/ /* What I want to have */ %put Timenow: %sysfunc(put(&time_, time13.)); /* Timenow: 22:06:00 */ %put DateNOw: %sysfunc(put(&time_, date9.)); /* DateNOw: 27FEB2019 */ %put TimeDifference: %sysfunc(put(&time_, time13.)); /* TimeDifference: 00:00:05 */ %mend; %test; 会给我带来类似的结果:%sysfunc(put(&time_, time13.)); 有没有简单而直接的方法可以做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:0)

SYSFUNC具有格式选项。考虑一下这是否对您有用。

%let time1 = %sysfunc(datetime());
   data _null_;
      timedelay = sleep(5, 1);
      run;
%let time2 = %sysfunc(datetime());

%let diff = %sysfunc(sum(&time2,-&time1),time13.);
%put NOTE: &=diff;

enter image description here

或者如果您想使用PUTN功能。

%put TimeDifference: %sysfunc(putN(%sysevalf(&time2-&time1),time,13));

enter image description here