BookmarkSubscribeRSS Feed
axescot78
Quartz | Level 8

I get an error like this:

 

NOTE: Invalid argument to function INPUT at line 110 column 167.

 

However, since it is in a macro, I don't have line numbers in the log to find the exact location. How do I find which line the error is occurring?

4 REPLIES 4
SASKiwi
PROC Star

Turn on the SAS MPRINT option and rerun your macro:

options mprint;

The SAS log should then show where the error is.

Also search through your macro to find where the SAS function INPUT is used.

Tom
Super User Tom
Super User

LINE and COLUMN really don't translate very well with macro code.

If you only have a couple of INPUT() function calls then just just the data for all of them.

 

You could turn on the MPRINT option and copy the generated code from the log and run that step again as plain old SAS code and then you will get a real line and column number to help you find the mistake.

 

You could also re-write the code to check for issues itself.

So if you have, for example something like this:

newvar = input(oldvar,yymmdd10.);

You could try making sure that the value is valid for that informat first.

if not missing(oldvar) and missing(input(oldvar,??yymmdd10.) then 
  put 'WARNING: Value of ' oldvar= 'is not valid for informat YYMMDD10.';
else newvar = input(oldvar,yymmdd10.);
Patrick
Opal | Level 21

The "best practice" approach for writing macros is to first write the code for a single use case without macro and fully debug it. Only then make the code dynamic via a macro.

Following this approach normally lets you fix issues like the one you encounter before you have to deal with anything macro.

 

If you've got it already in a macro then try if options mprint and eventually spool create enough log

%macro test();
  data _null_;
    xx=input('A',date.);
  run;
%mend;

options mprint spool;
%test();

 

If it's really bad then you could also use the mfile option. This lets you capture the macro generated SAS code and then execute this code separately with everything macro already resolved. 

filename mprint temp;
options mprint mfile;
%test();

%include mprint /source2;
options nomfile;
filename mprint clear;
32         %include mprint /source2;
NOTE: %INCLUDE (level 1) file MPRINT is file 
      ....\SAS Temporary Files\_TD20848_******_\#LN00166.
33        +data _null_;
34        +xx=input('A',date.);
35        +run;

NOTE: Invalid argument to function INPUT at line 34 column 4.
xx=. _ERROR_=1 _N_=1



Astounding
PROC Star

Here's a situation that will cause trouble with the INPUT function and macros.  I'm not sure if you would get the error message that you received or not, but here it is anyway.

 

If you are using %SYSFUNC, you cannot use it to call the INPUT function.  You would have to switch to INPUTC or INPUTN instead.  That's fairly easy to check in your code, to see if %SYSFUNC is being used to call the INPUT function, along these lines:

 

%let m = %sysfunc(input(.......

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 762 views
  • 1 like
  • 5 in conversation