DATA Step, Macro, Functions and more

input function unnecessarily converting numeric to characters

Reply
Contributor KAZ
Contributor
Posts: 25

input function unnecessarily converting numeric to characters

I am attempting to get rid of a NOTE in the log file. (v9.4, Windows)

 

I run the following code:

 

data _temp;	
	a=1; output; 
run;

data _temp2;	
	set _temp;
	b = input(a, best12.);
run;

 

In the log, there is this NOTE:

NOTE: Numeric values have been converted to character values at the places given by:

 

Both variables a and b are numeric, and best12. is numeric informat.  Why is the input function converting numeric values to character values?

 

Is there another function I should use to get rid of the NOTE in the log?

Super User
Posts: 6,938

Re: input function unnecessarily converting numeric to characters

Because input() is designed to input from strings, the numeric value in a must first be converted to character, so it can be read with the best12. informat.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 125

Re: input function unnecessarily converting numeric to characters

INPUT() function is used to convert character to numeric. In your example INPUT(a,best12.) --> Here 'a' must be given character values. Since you gave numeric value it converted to character and again ti numeric.

Thanks,
Suryakiran
Super User
Posts: 17,829

Re: input function unnecessarily converting numeric to characters

What are you trying to do?

 

 

Contributor KAZ
Contributor
Posts: 25

Re: input function unnecessarily converting numeric to characters

I am trying to use informats for data validation.

 

For example, the external data is expected to have three values 0, 1, and 99 to indicate unknown.  I want to return a variable with just 0 and 1, convert the 99 to missing and throw an error when other values are encountered.

 

 

data _externalData;	
	a=1; output; 
	a=0; output;
	a=77; output;
	a=99; output;
run;

proc format;
	invalue test	
		0-1 	= _same_
		99	= . 
		other 	= _error_
	;
run;

data _myData;	
	set _externalData;
	b = input(a, test.);
run;

The results are what I desire, I just want to get rid of the (seemingly) unnecessary NOTE in the log.  Should I be using another function besides input?

Super User
Posts: 6,938

Re: input function unnecessarily converting numeric to characters

Do

b = input(put(a,best.),test.);
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 125

Re: input function unnecessarily converting numeric to characters

data _externalData;

a=1; output;

a=0; output;

a=77; output;

a=99; output;

run;

proc format;

value tet

0 = 0

1 = 1

99 = .

other ="_error_"

;

run;

data _myData;

set _externalData;

b = put(a, test.);

run;

Thanks,
Suryakiran
Ask a Question
Discussion stats
  • 6 replies
  • 242 views
  • 0 likes
  • 4 in conversation