BookmarkSubscribeRSS Feed
yonib
SAS Employee
Hi,
Is there a diffrence between using Input function and zero ?
6 REPLIES 6
Patrick
Opal | Level 21
?????
I'm now very curious if someone will understand your question.
Flip
Fluorite | Level 6
Yes, there is.
milts
Pyrite | Level 9
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
Cynthia_sas
SAS Super FREQ
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]
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Wow, Cynthia - you are a true information / knowledge champion in my opinion!

Scott
yonib
SAS Employee
Hi Cynthia,
Thanks alot !!!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 808 views
  • 0 likes
  • 6 in conversation