DATA Step, Macro, Functions and more

NOTE: Invalid argument to function INPUT

Reply
Regular Contributor
Posts: 199

NOTE: Invalid argument to function INPUT

[ Edited ]

I'm using an array to convert character variables to numeric. The code executes w/o errors or warnings, but the notes state " NOTE: Invalid argument to function INPUT at line 80 column 16."

 

What's wrong w/ this syntax? Thanks for your help.

 

79 DO i=1 to dim(_char);

80 _num(i) = input(_char(i),6.);
81 END;

 

DATA conversion_subset;
	SET	dropping_strings;

 	Array _char(*) $ 
 	_100400
	_100500
 	_100600
 	_200100
 	_200200
	_200300
	_200400
	_200401
	_400402
	_400403
	_400601
	_400602
	
	_500800
	_500900
	_501000;
	
 	Array _num(*) var1-var15;
  	
  	DO i=1 to dim(_char);
     _num(i) = input(_char(i),6.); 
    END;
     
    DROP 
	_100400
	_100500
 	_100600
 	_200100
 	_200200
	_200300
	_200400
	_200401
	_400402
	_400403
	_400601
	_400602	
	_500800
	_500900
	_501000
	i; 
	
	RENAME
	VAR1	=	_100400
	VAR2	=	_100500
	VAR3	=	_100600
	VAR4	=	_200100
	VAR5	=	_200200
	VAR6	=	_200300
	VAR7	=	_200400
	VAR8	=	_200401
	VAR9	=	_400402
	VAR10	=	_400403
	VAR11	= 	_400601
	VAR12	=	_400602
	VAR13	=	_500800
	VAR14	=	_500900
	VAR15	=	_501000;
RUN;

 

Super User
Posts: 5,496

Re: NOTE: Invalid argument to function INPUT

The syntax is fine.  There may be something wrong with the data.  This is saying that one (or more) of the incoming character variables contains text that can't legitimately be converted to numeric.

 

You can get rid of the message by adding ??:

 

_num(i) = input(_char(i), ??6.);

 

That doesn't fix the problem, just covers it up.

Super User
Posts: 11,343

Re: NOTE: Invalid argument to function INPUT

As @Astounding says it is likely a data issue.

If I were worried about missing an intended conversion I would do a proc freq on the text variables.

For instance if the data has values that are displayed with accounting rules like (1234) to indicate that the value is negative you may not want that be set to missing as your current data would. Other likely things would be currency symbols or commas as part of the values.

Of course if you have incoming values like NULL or N/A or such and those are the only suspect values then you're golden.

Super User
Posts: 7,758

Re: NOTE: Invalid argument to function INPUT

Inspect your data.

The NOTE will also supply the number (_N_) of the current iteration when the transformation error happened, so you know which observation(s) was(were) the culprit.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,942

Re: NOTE: Invalid argument to function INPUT

Post some example test data (in the form of a datastep).  I would also check the structure of your data, why have 15 variables which seem to get assigned to a _xxxxx variable name?  Where does the _xxxxx even come from?  I would suggest for ease of doing anything to the data you normlise it, i.e. have a long dataset rather than a wide.  Now this code is just a guess:

data conversion_subset (keep=variable char_result result);
  set dropping_strings;
  length variable char_result $100 result 8;
  array var{15};
  array lab{15} ("100400","100500","100600","200100","200200","200300","200400","200401","400402","400403","400601","400602","500800","500900","501000");
  do i=1 to dim(var);
    variable=lab{i};
    char_result=var{i};
    result=input(var{i},best.);
    output;
  end;
run;

But what it should do is give you a dataset which looks something like:

VARIABLE          CHAR_RESULT     RESULT

100400               123                      123

100500               abc                       .

...

You will see its far easier to conver a column of data rather than lots of columns, and you also get the benefit of by group processing.  If later on you need a transposed output, then proc transpose at that point.  Doing the above will also show you quite clearly where a value has not been converted, and what it contains - see the "abc" and missing result.  You can then put data cleaning if statements around the result= step.

Ask a Question
Discussion stats
  • 4 replies
  • 1265 views
  • 1 like
  • 5 in conversation