DATA Step, Macro, Functions and more

WHERE clause with exclusion

Accepted Solution Solved
Reply
Regular Contributor
Posts: 218
Accepted Solution

WHERE clause with exclusion

I have the folowinf table, can someone tell me how do I get all score greater than or equals 17 (excluding Clurse_ID=Eng). I mean observations where Course_ID=Eng should not be in considered in this clause. Thanks.

 

 

DATA Apple.have;
input Student_ID $ Course_ID $ Score;
cards; 
F103 Bio 18
F103 Math 15
F103 Eng 16
F103 Che 15
F103 Math 20
F103 Phy 17
M101 Eng 20
M101 Bio 20
M101 Eng 10
M101 Math 18
RUN;

 

Output table:

F103 Bio 18
F103 Eng 16
F103 Math 20
F103 Phy 17
M101 Eng 20
M101 Bio 20
M101 Math 18

 


Accepted Solutions
Solution
‎11-17-2016 07:47 AM
Trusted Advisor
Posts: 1,572

Re: WHERE clause with exclusion

Add your conditions as:

 

DATA Apple.have;
input Student_ID $ Course_ID $ Score;
if score ge 17 or course_id eq 'ENG';
cards;
.... your data ...
;
run;

View solution in original post


All Replies
Solution
‎11-17-2016 07:47 AM
Trusted Advisor
Posts: 1,572

Re: WHERE clause with exclusion

Add your conditions as:

 

DATA Apple.have;
input Student_ID $ Course_ID $ Score;
if score ge 17 or course_id eq 'ENG';
cards;
.... your data ...
;
run;
Occasional Contributor
Posts: 8

Re: WHERE clause with exclusion


DATA WANT;
SET Apple.HAVE (WHERE =(Score >= 17 or Course_ID = 'Eng' ));
RUN;

 

 

Result :

The observation 7 is also included 

 

 


Obs Student_ID Course_ID Score

1 F103 Bio 18
2 F103 Eng 16
3 F103 Math 20
4 F103 Phy 17
5 M101 Eng 20
6 M101 Bio 20
7 M101 Eng 10
8 M101 Math 18

Super User
Posts: 19,822

Re: WHERE clause with exclusion

Posted in reply to monikka1991_gmail_com

monikka1991_gmail_com wrote:

 

Result :

The observation 7 is also included 

 


Sorry, what are you trying to say here?

 

Obs 2 & 7 would be excluded otherwise, but they're included because Course_ID="ENG"

Occasional Contributor
Posts: 8

Re: WHERE clause with exclusion

Yeah ..But mlogan desired output has not included the 7th observation [7 M101 Eng 10] . I just added that note .

Super User
Posts: 19,822

Re: WHERE clause with exclusion

Posted in reply to monikka1991_gmail_com

Ah, you're correct, good catch! 

 

But my guess is its an oversight on @mlogan part. I guess he can respond either way!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 282 views
  • 1 like
  • 4 in conversation