LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (November 2010, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 23 Nov 2010 10:59:57 -0500
Reply-To:   Jerry <i89rt5@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jerry <i89rt5@GMAIL.COM>
Subject:   SQL LIKE condition with macro variable

Hi,

Within PROC SQL, the "LIKE" condition is used to test for a matching pattern, and is case-sensitive.

Per SAS documentation at http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473693.htm

underscore (_) is used to match any single character.

percent sign (%) is used to match any sequence of zero or more characters.

any other character is used to matche that character.

Because the % and _ characters have special meaning in the context of the LIKE condition, the ESCAPE clause is used to search for these character literals in the input character string.

Here is my headache when I tried to use LIKE condition together with macro variable, see my example below

LIKE "%1234^_2010%" matches this value: pre1234_2010post

Now let me set up 2 macro variables to replace 1234 and 2010: %let id=1234; %let year=2010;

However, LIKE "%&id.^_&year.%" does not work, how to fix it?

Another example which may better explain my question is below, as it does not involve the underscore (_)

/*******THIS WORKS************/ proc sql noprint ; select memname into :dataset separated by ' ' from dictionary.members where libname = "SASHELP" AND MEMTYPE='DATA' AND MEMNAME like "Z%" ; quit;

%put "DATASET is &DATASET"; /********** In the log, you will see "DATASET is ZHC ZIPCODE ZIPMIL ZTC" **********/

/************ THIS does not WORKS, when I replace "z" with a macro variable &letter *************/ %let letter=z;

proc sql noprint ; select memname into :dataset separated by ' ' from dictionary.members where libname = "SASHELP" AND MEMTYPE='DATA' AND MEMNAME like "&letter%" ; quit;

%put "DATASET is &DATASET"; /*************** In the log, you will see this NOTE: No rows were selected. *****************/

Let me know if my question is not clear.

Thanks.


Back to: Top of message | Previous page | Main SAS-L page