BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bal23
Lapis Lazuli | Level 10

 

I saw a note, "Invalid argument to function INPUT"  on the log based on my sas code:

 

var1=input(substr(var2,1,3), 8.);

 

It shows that:

 

Mathematical operations could not be performed at the following places. The results of the
operations have been set to missing values.

 

Would anybody explain how it will affect my results? How to fix it?

Thanks.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Create a new variable that is only the substr function, what you're using in the input() function. Then run a proc freq on that. Consider what the input() function is expecting and visually examining your data should give you a clear view of what's causing the issue. 

data check;
set have;
var_check=substr(var, 1, 3);
run;

proc freq data=check;
table var_check;
run;

 

View solution in original post

6 REPLIES 6
Reeza
Super User

The note will also give you the record number of where the issue occurred so you can check your actual data.

 

It means that var1 will be set to missing when the substr() function does not return a valid value. Check what your substr() is returning and decide if you need to deal with those cases or if setting it to missing is fine. 

 

A general rule is to not allow notes like that in your log though, because it makes error checking later on difficult.

Bal23
Lapis Lazuli | Level 10

Thank you. How to find how much missing data it generates?

 

WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.

ballardw
Super User

@Bal23 wrote:

Thank you. How to find how much missing data it generates?

 

WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.


The number of records with the error message are determined by the SAS system option Errors. You can change that by using code:

options errors=50;

 

The default is usually 20. Look at the results of the first 20 errors and see if you can identify the pattern of values that are causing the error.

Is the variable VAR1 text or numeric? Are there any characters in the first 3 of Var1 that are not numerals or decimal?

You will get that error if VAR1 has a value like "1 3245" or 1_234

 

Bal23
Lapis Lazuli | Level 10

would you please let me know how to

 

"Check what my substr() is returning" ?

 

 

Thanks.

Reeza
Super User

Create a new variable that is only the substr function, what you're using in the input() function. Then run a proc freq on that. Consider what the input() function is expecting and visually examining your data should give you a clear view of what's causing the issue. 

data check;
set have;
var_check=substr(var, 1, 3);
run;

proc freq data=check;
table var_check;
run;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 9875 views
  • 0 likes
  • 4 in conversation