Input 避免出现SAS错误消息:“quot;注意:函数输入的参数无效;

Input 避免出现SAS错误消息:“quot;注意:函数输入的参数无效;,input,sas,Input,Sas,有没有办法测试变量在SAS中的输入转换过程中是否会失败?或者,如果可以避免产生“NOTE:Invalid argument”消息 data _null_; format test2 date9.; input test ; test2=INPUT(PUT(test,8.),yymmdd8.); if _error_ =1 then do; _error_=0; test2=INPUT(PUT(test-1,8.),yymmdd8.); end; p

有没有办法测试变量在SAS中的输入转换过程中是否会失败?或者,如果可以避免产生“NOTE:Invalid argument”消息

data _null_;  
format test2 date9.;  
input test ;  
test2=INPUT(PUT(test,8.),yymmdd8.);  
if _error_ =1 then do;  
    _error_=0;  
    test2=INPUT(PUT(test-1,8.),yymmdd8.);  
end;  
put test2=;  
cards;  
20270229  
run;  

不必这样做,您可以先将变量视为字符变量(因为您知道有些值不是实际日期),然后使用来帮助您找到无效值,然后修复这些值,然后在所有数据清除后将变量转换为数字变量。

只需包含“?”在格式名称之前。您的示例已修改如下

data null;
format test2 date9.;
input test ;
test2=INPUT(PUT(test,8.),?? yymmdd8.);
if error =1 then do;
error=0;
test2=INPUT(PUT(test-1,8.), ?? yymmdd8.);
end;
put test2=;
cards;
20270229
run;

您可以使用类似以下内容进行检查:

data null;
  format test2 date9.;
  input test ;
  test2=INPUT(PUT(test,8.),yymmdd8.);
  **if test ne '' and nmiss(test2)** then test2=INPUT(PUT(test-1,8.),yymmdd8.);
  put test2=;
cards;
20270229
run;

感谢这一点,但是日期直接来自一系列大的、列分隔的平面文件-如果我要读取两次数据,这将大大增加处理时间。另外,(我可能错了),但就转换资源而言,上面的方法不是更有效吗?我认为使用单一的方法会更好吗?而不是双??在输入函数中。这样,他仍然可以访问error变量,用于数据步骤中的其余逻辑。否则,错误将保持在0。