DATA Step, Macro, Functions and more

Input function against 0

Reply
SAS Employee
Posts: 105

Input function against 0

Hi,
Is there a diffrence between using Input function and zero ?
Respected Advisor
Posts: 3,887

Re: Input function against 0

?????
I'm now very curious if someone will understand your question.
Super Contributor
Posts: 359

Re: Input function against 0

Yes, there is.
Super Contributor
Posts: 316

Re: Input function against 0

input function is used to covert character values into numeric values. i just don't get why compare it to zero. they are totally different
SAS Super FREQ
Posts: 8,740

Re: Input function against 0

Hi:
It seems to me that the original question must be part of a bigger question or issue. Since the INPUT function is used (as already explained) to convert a character variable value to a numeric variable value, the result of the INPUT function may not be as you expect. Consider the following program:
[pre]
data convert;
infile datalines;
input string $;
newvar = input(string,best.);
return;
datalines;
0
1
33333
fred
.4
;
run;
[/pre]

The INPUT function will be able to convert all the character strings to numbers except on observation 4. The string 'fred' is not a number. When the INPUT function is used on this value, you will:
1) get an ERROR=1 condition and a NOTE in the SAS log and
2) get a missing value in the numeric variable, as shown below:
[pre]
NOTE: Invalid argument to function INPUT at line 129 column 12.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+
135 fred
string=fred newvar=. _ERROR_=1 _N_=4
[/pre]

If you then run the PROC PRINTs (shown at the end), you will get the output as shown at the bottom of this post.

It might be possible, if you wanted to use 0 or 1 in Boolean expressions, that you might use the INPUT function to convert character zeroes or ones into a number so the Boolean expression would work without a warning about automatic conversion from character to numeric, but still, if you're not very sure about your data, the INPUT function could return something other than 0 or 1.

cynthia

[pre]
142 proc print data=convert;
143 title 'Using the INPUT function';
144 run;

NOTE: There were 5 observations read from the data set WORK.CONVERT.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

145
146 proc print data=convert;
147 title 'What values are 0';
148 where newvar = 0;
149 run;

NOTE: There were 1 observations read from the data set WORK.CONVERT.
WHERE newvar=0;
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

150
151 proc print data=convert;
152 title 'What values are missing';
153 where newvar = .;
154 run;

NOTE: There were 1 observations read from the data set WORK.CONVERT.
WHERE newvar=.;
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

[/pre]

The Results from the LISTING window:
[pre]
***First PROC PRINT:

Using the INPUT function

Obs string newvar
1 0 0.0
2 1 1.0
3 33333 33333.0
4 fred .
5 .4 0.4


***Second PROC PRINT:

What values are 0

Obs string newvar
1 0 0

***Third PROC PRINT:

What values are missing

Obs string newvar
4 fred .

[/pre]
Super Contributor
Super Contributor
Posts: 3,174

Re: Input function against 0

Wow, Cynthia - you are a true information / knowledge champion in my opinion!

Scott
SAS Employee
Posts: 105

Re: Input function against 0

Hi Cynthia,
Thanks alot !!!!
Ask a Question
Discussion stats
  • 6 replies
  • 178 views
  • 0 likes
  • 6 in conversation