Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date SAS无效';闰年';发行日期yymmdd8_Date_Sas - Fatal编程技术网

Date SAS无效';闰年';发行日期yymmdd8

Date SAS无效';闰年';发行日期yymmdd8,date,sas,Date,Sas,我正在读一些原始数据,其中有几个糟糕的日期。特别是,有人在非闰年输入了“2月29日”。例如: data _null_; input test :yymmdd8.; format test date9.; cards; 20270229 run; 客户希望恢复到2月28日。有没有快速/有效的方法?例如,相当于: 如果iserror(日期),则日期=日期-1 感谢您的建议 这里有一个来自SCONSIG的好提示 可以通过一种或另一种方式将其合并到负载中 这并不漂亮,有转换说明,但它可以工作,不会出错

我正在读一些原始数据,其中有几个糟糕的日期。特别是,有人在非闰年输入了“2月29日”。例如:

data _null_;
input test :yymmdd8.;
format test date9.;
cards;
20270229
run;
客户希望恢复到2月28日。有没有快速/有效的方法?例如,相当于:

如果iserror(日期),则日期=日期-1


感谢您的建议

这里有一个来自SCONSIG的好提示


可以通过一种或另一种方式将其合并到负载中

这并不漂亮,有转换说明,但它可以工作,不会出错

data testit;
   format test2 yymmdd10.;
   input x $8.;
   mod4 = mod(mod((substr(x,1,4)/4),4) * 10,10);   
   if mod4 NE 0 then x = x - 1;
   test2=input(x,yymmdd8.);
   put x= test2=;

cards;
20080229
20090229
20100229
20110229
20120229
20130229
20270229
run; 
输出:

x=20080229 test2=2008-02-29
x=20090228 test2=2009-02-28
x=20100228 test2=2010-02-28
x=20110228 test2=2011-02-28
x=20120229 test2=2012-02-29
x=20130228 test2=2013-02-28
x=20270228 test2=2027-02-28
对上述答案稍加修改(我认为)。它通过在输入函数中使用“?”来避免错误消息

data testit;
   format indate yymmdd10.;
   input x $8.;

   indate = input(x, ?? yymmdd8.);
   if indate=. then indate= input(put(x - 1, 8.), ?? yymmdd8.);


    put indate=;

cards;
20080229
20090229
20100229
20110229
20120229
20130229
20270229
run;

我会更仔细地确定日期。这里有一个方法。嗯

%put sysvlong=&sysvlong sysscpl=&sysscpl;           
/* sysvlong=9.02.01M0P020508 sysscpl=W32_VSPRO */

/* read a date both as character(temp) and numeric(date).
   if the numeric date is missing then check if the
   character date ends with "0229," if so, then change it
   to "0228" and see if it is a valid date. 
   If OK, then that is it. otherwise, keep it missing. */
%let FEB29 = 0229; 
%let FEB28 = 0228;
data one;
  drop temp;
  input temp $char8. @1 date ?? yymmdd8.;
  if missing(date) then link fix;
  format date b8601da.;
  put (_all_) (=);
  return;
fix:
  if length(strip(temp))^=8 then return;
  if substr(temp,5) ^= "&FEB29" then return;
  date = input(cat(substr(temp,1,4), "&FEB28"), ?? yymmdd8.);
return;
cards;
20080229  ok
20090229  should be changed to 28th
201XX229  this should be missing
20110229  -> 28
20120229  ok 
20130229  -> 28
20270229  -> 28
;
run;

/* on log
temp=20080229 date=20080229
temp=20090229 date=20090228
temp=201XX229 date=.
temp=20110229 date=20110228
temp=20120229 date=20120229
temp=20130229 date=20130228
temp=20270229 date=20270228
NOTE: The data set WORK.ONE has 7 observations and 1 variables.
*/

谢谢你,我现在正在尝试一种不同的方法(发布了一个新的问题),但是如果我不能摆脱错误信息,我想我会用它来代替(将年份放入一个宏观变量)。很好的代码!谢谢..喜欢这个??修改器!
%put sysvlong=&sysvlong sysscpl=&sysscpl;           
/* sysvlong=9.02.01M0P020508 sysscpl=W32_VSPRO */

/* read a date both as character(temp) and numeric(date).
   if the numeric date is missing then check if the
   character date ends with "0229," if so, then change it
   to "0228" and see if it is a valid date. 
   If OK, then that is it. otherwise, keep it missing. */
%let FEB29 = 0229; 
%let FEB28 = 0228;
data one;
  drop temp;
  input temp $char8. @1 date ?? yymmdd8.;
  if missing(date) then link fix;
  format date b8601da.;
  put (_all_) (=);
  return;
fix:
  if length(strip(temp))^=8 then return;
  if substr(temp,5) ^= "&FEB29" then return;
  date = input(cat(substr(temp,1,4), "&FEB28"), ?? yymmdd8.);
return;
cards;
20080229  ok
20090229  should be changed to 28th
201XX229  this should be missing
20110229  -> 28
20120229  ok 
20130229  -> 28
20270229  -> 28
;
run;

/* on log
temp=20080229 date=20080229
temp=20090229 date=20090228
temp=201XX229 date=.
temp=20110229 date=20110228
temp=20120229 date=20120229
temp=20130229 date=20130228
temp=20270229 date=20270228
NOTE: The data set WORK.ONE has 7 observations and 1 variables.
*/