Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'IF' and 'SET' statements

Status
Not open for further replies.

screwSAS

Technical User
Feb 10, 2009
4
US
I have imported a file from excel, it works. However I'm trying to modify it for analysis. This is the error I get and here is a copy of what I have coded. WHAT am I doing wrong???

data sasuser.pedifalls;
set sasuser.pedifalls;
if graf6='<=1' then graf6 ='0';
else if graf6='>=2' then graf6='1';
proc freq; table graf6;
run;


NOTE: Invalid numeric data, '<=1' , at line 12500 column 10.
NOTE: Invalid numeric data, '>=2' , at line 12501 column 15.
ERROR: Limit set by ERRORS= option reached. Further errors of this type will not be printed


Also, if I change the 'set' or take away the quotes from the new values, it gives an error of missing infile statement and that no data file exists. I simply don't know how to use the if statement. I appreciate any help, thanks.
 
Are the values in graf6 literally "<=1 and ">=2", or are you trying to say if the value in graf6 is less than or equal to 1 (or greater than/equal to 2)?

If they are literally "<=1 and ">=2", then your code looks ok. For example, using your code plus a small sample dataset, the following runs without any errors.
Code:
data have;
input item $ graf6 $;
datalines;
A	<=1
D	>=2
C	<=1
F	>=2
G	<=1
;
run;

data have;
set have;
if graf6='<=1' then graf6 ='0';
else if graf6='>=2' then graf6='1';
proc freq; table graf6; 
run;

I would check your dataset using the row/column from the error message (line 12500 column 10) to make sure the values that are there are what you expect to be there.

However, if the values in graf6 are not literally "<=1 and ">=2" and are numbers, then you'd need to remove the quotes from your code. Like this:
Code:
data have;
set have;
if graf6<=1 then graf6 =0;
else if graf6>=2 then graf6=1;
proc freq; table graf6; 
run;

~Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top