SAS YYMMDD10。有效,但YYMMDDn10无效

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

这是我的数据(对不起,没有脚本,它只是从mssql proc创建表):

testdb.testtable
id - numeric
date_from - numeric (datetime from mssql)
date_to - numeric (datetime from mssql)
base_id - numeric
base_id2 - string (length 64)

我试图做的是:

proc sql;
update testdb.testtable tt
set base_id2 = CATX('_',
    ('data from other table'),
    put(datepart(date_from),yymmddn10.),
    put(datepart(date_to),yymmddn10.),
    put(base_id,z4.)
)
where (....)
;
quit;

我收到此错误:

The width value for YYMMDDN is out of bounds. It should be between 2 and 8.
The width value for YYMMDDN is out of bounds. It should be between 2 and 8.

我真的不明白,当我使用带分隔符的格式YYMMDD10时,它可以工作。

当我跑步时:

proc sql;
select datepart(date_from) format=yymmddn10. from testdb.testtable;
quit;

返回20191227-太好了。当我运行

proc sql;
select put(datepart(date_from),yymmddn10.) from testdb.testtable;
quit;

它失败,并出现相同的错误。

我想念什么?

sql datetime sas format put
2个回答
3
投票

PROC SQL中似乎存在一个错误,该错误允许您附加无法使用的格式(不带分隔符的日期的最大宽度为8个字节)。

[有趣的是,PROC PRINT(以及您的示例中的PROC SQL中的简单SELECT查询)不介意格式宽度无效。

542   data test1;
543     now=date();
544   run;

NOTE: The data set WORK.TEST1 has 1 observations and 1 variables.

545
546   data test2 ;
547     set test1;
548     format now yymmddn10.;
                   ----------
                   29
ERROR 29-185: Width specified for format YYMMDDN is invalid.

549   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEST2 may be incomplete.  When this step was stopped there were 0 observations
         and 1 variables.
WARNING: Data set WORK.TEST2 was not replaced because this step was stopped.

550
551   proc sql;
552   create table test2 as select now format=yymmddn10. from test1;
NOTE: Table WORK.TEST2 created, with 1 rows and 1 columns.

553   select * from test2;
554   quit;


555
556   proc print data=test2;
557   run;

NOTE: There were 1 observations read from the data set WORK.TEST2.

558
559   data test3;
560     set test2;
561   run;

ERROR: Width specified for format YYMMDDN is invalid.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEST3 may be incomplete.  When this step was stopped there were 0 observations
         and 1 variables.
WARNING: Data set WORK.TEST3 was not replaced because this step was stopped.

同样有趣的是,如果您在PROC FREQ中使用该格式规范,则>

proc freq data=test2; tables now; run;

它在数据字符串前添加一个空格和'F7'x字符。

The FREQ Procedure

                                       Cumulative    Cumulative
       now    Frequency     Percent     Frequency      Percent
---------------------------------------------------------------
 ÷20200218           1      100.00             1       100.00

1
投票

格式中的数字是给定的宽度。格式YYMMDDn有8个字符,所以我应该使用YYMMDDn8。而且有效。

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