Thursday, August 5, 2010

Use of LIKE in proc sql

Look at the Customer Table, and say you wanted to see all people whose last names started with "m"; The syntax would be:

data customer;
input Cust_F_name $5. Cust_L_Name $4. id;
cards;
anjo bana 201
minu mana 211
sinu shan 444
sinu malu 442
;run;

proc sql;
SELECT id, Cust_F_name
FROM customer
WHERE Cust_L_Name LIKE 'm%';
quit;

The percent sign (%) is used to represent any possible character (number, letter, or punctuation) or set of characters that might appear after the "m". To find those people with LastName's ending in "m", use '%m', or if you wanted the "m" in the middle of the word, try '%m%'. The '%' can be used for any characters in the same position relative to the given characters. NOT LIKE displays rows not fitting the given description.

No comments:

Post a Comment