Like Operator in SAS Programming

LIKE Operator: Pattern Matching

The LIKE operator used to select data by comparing the values of a character variable to a specified pattern. It is case sensitive.

Task 1: To select all students with a name that starts with the letter S.

There are two special characters patterns available for specifying a pattern:

  • percent sign (%) – Wildcard Character

  • underscore ( _ ) – Fill in the blanks

filter_none

edit
close

play_arrow

link
brightness_4
code

data readin;
input name $ Section $ Score;
cards;
Raj  A 80
Atul . 77
Priya . 45
Sandy A 67
David B 39
Rahul . 95
Sahil C 84
Savitri B 65
;
run;
  
data readin1;
set readin;
where name like 'S%';
run;

chevron_right


Output:

In a given dataset, the above statements would produce the same result in both cases.

Examples:

  1. where name like '%ul';

    Output:

    It contains all the data where the name ends with ‘ul’.

  2. where name like '_ah%';

    Output:

    It contains all the data where the name contains atleast 3 characters, which must contain ‘ah’ at second place.

  3. where name like '_a___';

    Output:

    It contains all the data where the name contains atleast 5 characters, which must contain ‘a’ at second place.



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.