BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rylife
Fluorite | Level 6
Original Code
 
Data scoredata_ifthen;
set scoredata0;
TotalScore= sum(score1, score2, score3);
AverageScore= mean(score1, score2, score3);
/* Using the IF...THEN...statement*/
IF gender ='m' THEN gender_num=1;
IF score1 NE. AND score2 NE. AND score3 NE. THEN take='complete';
IF AverageScore GE 90 THEN DO;
grade= 'A';
pass= 'pass';
END;
run;
 
 
After running code
OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 Data scoredata_ifthen;
74 set scoredata0;
75 TotalScore= sum(score1, score2, score3);
76 AverageScore= mean(score1, score2, score3);
77 /* Using the IF...THEN...statement*/
78 IF gender ='m' THEN gender_num=1;
79 IF score1 NE. AND score2 NE. AND score3 NE. THEN take='complete';
___
388
201
76
ERROR 388-185: Expecting an arithmetic operator.
 
ERROR 201-322: The option is not recognized and will be ignored.
 
ERROR 76-322: Syntax error, statement will be ignored.
 
80 IF AverageScore GE 90 THEN DO;
81 grade= 'A';
82 pass= 'pass';
83 END;
84 run;
 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

correction;

 

you missed a blank in NE.  that is between NE and .

 

IF score1 NE . AND score2 NE . AND score3 NE . THEN take='complete';

Your original code below

IF score1 NE. AND score2 NE. AND score3 NE. THEN take='complete';

is causing tokenizaion problem at compile time

 

 

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

correction;

 

you missed a blank in NE.  that is between NE and .

 

IF score1 NE . AND score2 NE . AND score3 NE . THEN take='complete';

Your original code below

IF score1 NE. AND score2 NE. AND score3 NE. THEN take='complete';

is causing tokenizaion problem at compile time

 

 

rylife
Fluorite | Level 6
Thank you!
Amir
PROC Star

@novinosrin has identified the issue and corrective action.

 

As an alternative, one can also make use of the missing function, e.g.:

 

if not missing(score1) and not missing(score2) and not missing(score3) then take='complete';

or, in your specific case, the nmiss function could also be of help, as it counts the number of missing numeric values, e.g.:

 

if nmiss(score1,score2,score3) eq 0 then take='complete';

 

Regards,

Amir.

 

rylife
Fluorite | Level 6

Thank you!

ballardw
Super User

If you want to do something when all values of numeric values are present you might want to consider the NMISS function instead of a bunch of If this and that and somethinelse comparisons:

 

If Nmiss(Score1, score2, score3) = 0 then take='complete';

 

if you have a lot of value you can even use list notation to reduce coding such as:

 

if nmiss( of score1-score25) =0 then take='complete';

which would certainly be a whole lot easier than 25 AND comparisons.

rylife
Fluorite | Level 6

Thank you, this will be useful once I use larger data sets. 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 15579 views
  • 3 likes
  • 4 in conversation