1

考虑以下:

data; 
format x datetime19.;
x=datetime();
flag='FIRST';
do x=datetime() to x+10 by 1;
    output;
    flag='';
end;
proc sql noprint;
select x into : test1 from &syslast where flag='FIRST';
select max(x) into: test2 from &syslast;
%put now we see that &test1 is in a different format to &test2;

data _null_;  set;
put x=; /* formatted */
call symput('test3',x);
call symput('test4',max(x,sum(x+1000)));
stop;
run;
%put The data step is more consistent - &test3 = &test4;

对我来说似乎不一致。为什么 proc sql 在这种情况下保留格式?这种行为是否记录在案?

4

2 回答 2

3

SAS 无法知道函数的结果应该如何格式化。在这种情况下,您的max()函数只是返回一个日期时间,但是如果其中有嵌套函数或算术怎么办。因为这个 SAS 只是将其视为一个全新的变量,默认情况下没有设置格式。如果您想对其应用相同的格式,您可以将代码更改为:

select max(x) format=datetime19. into: test2 from &syslast;
于 2012-10-02T14:35:57.063 回答
2

在您的示例中,该MAX函数创建一个新列,并且在创建新列时,您需要指定所有列属性。因此,只需FORMAT在您的 select 语句中添加一个子句:

proc sql noprint;
    select x into : test1 from &syslast where flag='FIRST';
    select max(x) format=datetime19. into: test2 from &syslast;
quit;
%put now we see that &test1 is in a different format to &test2;
于 2012-10-02T14:39:12.817 回答