LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2012, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 6 Mar 2012 12:57:48 -0500
Reply-To:     Bolotin Yevgeniy <YBolotin@SCHOOLS.NYC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Bolotin Yevgeniy <YBolotin@SCHOOLS.NYC.GOV>
Subject:      Re: Using the LIKE operator in PROC SQL XXXX
Comments: To: Dan Abner <dan.abner99@GMAIL.COM>
In-Reply-To:  A<CAPRGo-=yxcgE8_=ZHiqMijSQX9xMm2HU9OCmiMRX2MUJrmxFfA@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"

Might want to do something like this:

%let a = hello!; %let x=%sysfunc(substr(&a.,1,3)); %put &x.;

you will get a warning if &a is shorter than 3, but you will never get a false positive out of it

then: %if &x. = R_ %then ...

The more recent SAS versions support the IN statement for macro logic, but it requires enabling the system option MINOPERATOR

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Dan Abner Sent: Tuesday, March 06, 2012 12:51 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Using the LIKE operator in PROC SQL XXXX

Actually, how about multiple or's:

%IF &VAR1 (begins with R_ or Q_ or N_) %THEN ....

On Tue, Mar 6, 2012 at 12:49 PM, Dan Abner <dan.abner99@gmail.com> wrote: > On the same subject, what is the best (most efficient) way to specify > a begins with logical expression at the macro level? > > %IF &VAR1 (begins with R_) %THEN .... > > Thanks! > > Dan > > > > On Tue, Mar 6, 2012 at 12:41 PM, Zdeb, Michael S <mzdeb@albany.edu> wrote: >> hi ... that's correct and a possible work around is to lenghten the argument on the left ... >> >> >> data x; >> input var1 : $5. @@; >> datalines; >> R_890 R2999 qwert R_ r_1 R >> ; >> >> proc sql; >> select * from x where upcase(catt(var1,'*')) eqt 'R_'; >> quit; >> >> >> >> Mike Zdeb >> U@Albany School of Public Health >> One University Place (Room 119) >> Rensselaer, New York 12144-3456 >> P/518-402-6479 F/630-604-1475 >> >> ________________________________________ >> From: SAS(r) Discussion [SAS-L@LISTSERV.UGA.EDU] on behalf of Bolotin Yevgeniy [YBolotin@SCHOOLS.NYC.GOV] >> Sent: Tuesday, March 06, 2012 12:17 PM >> To: SAS-L@LISTSERV.UGA.EDU >> Subject: Re: Using the LIKE operator in PROC SQL XXXX >> >> T = truncate :) >> >> But be careful in its use - since it's *exactly* like =:, it truncates >> to the shortest value on the right OR the left: >> >> a = 'R'; >> ... >> where a EQT 'R_' >> ... >> >> >> this will result in a positive match, even though that's probably not >> the expected outcome >> >> >> >> >> >> >> -----Original Message----- >> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Dan >> Abner >> Sent: Tuesday, March 06, 2012 11:33 AM >> To: SAS-L@LISTSERV.UGA.EDU >> Subject: Re: Using the LIKE operator in PROC SQL XXXX >> >> Hi Mike, >> >> This does work, but I'm not sure why. Isn't EQT an abbreviation for >> equals to? Please provide a URL for the documentation that discusses >> this. >> >> Thanks! >> >> Dan >> >> >> On Tue, Mar 6, 2012 at 11:20 AM, Zdeb, Michael S <mzdeb@albany.edu> >> wrote: >>> hi ... if you just want values that start with R_ you could always >> avoid LIKE and use EQT ... >>> >>> WHERE UPCASE(var1) EQT "R_"; >>> >>> Mike Zdeb >>> U@Albany School of Public Health >>> One University Place (Room 119) >>> Rensselaer, New York 12144-3456 >>> P/518-402-6479 F/630-604-1475 >>> >>> ________________________________________ >>> From: SAS(r) Discussion [SAS-L@LISTSERV.UGA.EDU] on behalf of Dan >> Abner [dan.abner99@GMAIL.COM] >>> Sent: Tuesday, March 06, 2012 10:28 AM >>> To: SAS-L@LISTSERV.UGA.EDU >>> Subject: Using the LIKE operator in PROC SQL XXXX >>> >>> Hi everyone, >>> >>> When using the LIKE operator in a WHERE clause of a call to PROC SQL, >>> the underscore (_) and percent signs (%) are special wildcard >>> characters. How does one specify an actual underscore in these >>> statements? >>> >>> I want to select only those obs where var1 begins with R_ >>> >>> I tried: >>> >>> WHERE UPCASE(var1) LIKE "R%STR(_)%"; >>> >>> but that does not work. >>> >>> Any help is appreciated! >>> >>> Thanks! >>> >>> Dan


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