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
data readin;input name $ Section $ Score;cards;Raj A 80Atul . 77Priya . 45Sandy A 67David B 39Rahul . 95Sahil C 84Savitri B 65;run; data readin1;set readin;where name like 'S%';run; |
In a given dataset, the above statements would produce the same result in both cases.
Examples:
where name like '%ul';
It contains all the data where the name ends with ‘ul’.
where name like '_ah%';
It contains all the data where the name contains atleast 3 characters, which must contain ‘ah’ at second place.
where name like '_a___';
It contains all the data where the name contains atleast 5 characters, which must contain ‘a’ at second place.






