Where Statement in SAS Programming

The WHERE statement is a substitute to IF statement when it comes to subsetting a data set.

Syntax:

WHERE (condition is true) => It refers to subsetting a dataset.



Task1 : Suppose you want to select only section A students. You need to filter Section variable equals to A using where clause.

filter_none

edit
close

play_arrow

link
brightness_4
code

data readin;
input name $ Section $ Score;
cards;
Raj  A 80
Atul A 77
Priya B 45
Sandeep A 95
Rahul C 84
Shreya C 44
;
run;
  
data readin1;
set readin;
where Section EQ "A";
run;

chevron_right


where section EQ “A” => This would tell SAS to select only section which is equals to values “A”.

You can also write where section = “A”. This statement serves the same purpose.

Output:

LOGICAL OPERATORS

Symbolic Mnemonic Meaning
& AND Both conditions true
| OR Either condition true
~ or ^ NOT Reverse the statement

Task2: Suppose you want to select section A and B students. You need to filter Section variable
equals to A or B using where clause.

filter_none

edit
close

play_arrow

link
brightness_4
code

data readin;
input name $ Section $ Score;
cards;
Raj  A 80
Atul A 77
Priya B 45
Sandeep A 95
Rahul C 84
Shreya C 44
;
run;
  
data readin1;
set readin;
where Section IN ("A" "B");
run;

chevron_right


where section IN (“A” “B”) => This would tell SAS to select those record where section is equals to either A or B values.

Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.