Table of Contents
The LIKE operator in PROC SQL is a useful tool for implementing the SAS syntax in SQL queries. It allows for pattern matching and wildcard searches, similar to the LIKE function in SAS. By using the LIKE operator, we can specify a pattern or a set of characters to search for in a specific column or string of data. This can be particularly helpful when dealing with large datasets or when trying to find specific values within a dataset. The LIKE operator follows the same syntax as the SAS LIKE function, making it easy for SAS users to adapt their knowledge and skills to PROC SQL. By incorporating the LIKE operator into our PROC SQL queries, we can efficiently and effectively carry out complex data manipulations and analysis tasks.
SAS: Use LIKE Operator in PROC SQL
You can use the LIKE operator in the PROC SQL statement in SAS to return rows where a variable in a dataset matches some string pattern.
The following example shows how to use the LIKE operator in practice.
Example: Using LIKE Operator in PROC SQL in SAS
Suppose we have the following dataset in SAS that contains information about various basketball players:
/*create dataset*/
data my_data;
input team $ points;
datalines;
Cavs 12
Cavs 14
Warriors 15
Hawks 18
Mavs 31
Mavs 32
Mavs 35
Celtics 36
Celtics 40
;
run;
/*view dataset*/
proc printdata=my_data;

We can use the LIKE operator in PROC SQL to select only the rows where the team contains the pattern ‘avs’ somewhere in the name:
/*select all rows where team contains 'avs'*/
proc sql;
select *
from my_data
where team like '%avs%';
quit;
Notice that only the rows where the team contains ‘avs’ somewhere in the name are returned.
The opposite of the LIKE operator in PROC SQL is NOT LIKE, which selects rows where some variable in a dataset does not contain a certain string pattern.
The following code shows how to use the NOT LIKE operator to select all rows where the team does not contain ‘avs’ in the name:
/*select all rows where team does not contain 'avs'*/
proc sql;
select *
from my_data
where team not like '%avs%';
quit;
Notice that only the rows where the team does not contain ‘avs’ somewhere in the name are returned.
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can we use the LIKE operator in PROC SQL to implement the SAS syntax?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-we-use-the-like-operator-in-proc-sql-to-implement-the-sas-syntax/
stats writer. "How can we use the LIKE operator in PROC SQL to implement the SAS syntax?." PSYCHOLOGICAL SCALES, 25 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-we-use-the-like-operator-in-proc-sql-to-implement-the-sas-syntax/.
stats writer. "How can we use the LIKE operator in PROC SQL to implement the SAS syntax?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-we-use-the-like-operator-in-proc-sql-to-implement-the-sas-syntax/.
stats writer (2024) 'How can we use the LIKE operator in PROC SQL to implement the SAS syntax?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-we-use-the-like-operator-in-proc-sql-to-implement-the-sas-syntax/.
[1] stats writer, "How can we use the LIKE operator in PROC SQL to implement the SAS syntax?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can we use the LIKE operator in PROC SQL to implement the SAS syntax?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
