Avoid the SAS error message: "NOTE: Invalid argument for INPUT function"

Is there a way to check if a variable will change the INPUT process in SAS? Or, alternatively, if you can get the message "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; 
+4
source share
3 answers

Just turn on "??" before the format name. Your example has been modified below ...

 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; 
+5
source

Instead, you can treat your variable as a character variable first (since you know that some of the values ​​are not real dates), then use the macro provided by AFHood to help you find invalid values, then fix these values, and then convert the variable to numeric var, as soon as all data is clean.

+1
source

You can check using something like the following:

 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; 
0
source

All Articles