|Date: ||Wed, 19 Apr 2006 10:27:29 -0400|
|Reply-To: ||"Dorfman, Paul" <paul.dorfman@FCSO.COM>|
|Sender: ||"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>|
|From: ||"Dorfman, Paul" <paul.dorfman@FCSO.COM>|
|Subject: ||Re: data step vs Proc sql|
The clarification seem to conform to your thoroughly wholesome nature :).
Frankly, the failure of WHEN to act like (no pun) WHERE does not surprise
me too much, for I would instinctively expect it to accept the same set of
operators as IF. After all, the case structure is nothing else but the
beatified bunch of IF-THEN-ELSEs, or IF-GOTOs, if one should prefer.
That is not to say that I would not like IF/WHEN to be able to accept all
operators not available to it but available to WHERE, and maybe even the
other way around as well, which would be the best of both worlds - for if
all operators were shared, we would not have to dwell on which are
applicable where, and it would likely make SAS code more robust.
However, while I am pretty sure all WHERE operators can be - given the due
diligence and sense of necessity - implemented for IF/WHEN, I doubt the
reverse is true - perhaps because WHERE tends to be standardized with SQL
in minds first; but I would not be surprised if I were wrong on this
On Wed, 19 Apr 2006 08:40:24 -0400, Ed Heaton <EdHeaton@WESTAT.COM> wrote:
>Nobody responded about the SELECT block in the DATA step. It doesn't
>allow the LIKE operator. To expand from Venky's example.
>NOTE: SAS (r) 9.1 (TS1M3)
>NOTE: This session is executing on the XP_PRO platform.
>NOTE: SAS 9.1.3 Service Pack 3
>1 Data _null_ ;
>2 Set sasHelp.Class ;
>3 Select ;
>4 When ( upCase(Name) like "JA%" ) then put Name = ;
>ERROR 22-322: Syntax error, expecting one of the following:
> !, !!, &, ), *, **, +, ',', -, /, <, <=, <>, =, >, ><,
> >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL,
> NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.
>ERROR 76-322: Syntax error, statement will be ignored.
>5 Otherwise ;
>6 End ;
>7 Run ;
>NOTE: The SAS System stopped processing this step because of errors.
>NOTE: DATA statement used (Total process time):
> real time 0.30 seconds
> cpu time 0.09 seconds
>From: email@example.com [mailto:firstname.lastname@example.org]
>On Behalf Of EvilPettingZoo97@aol.com
>Sent: Friday, April 14, 2006 2:56 PM
>To: swovcc@HOTMAIL.COM; SAS-L@listserv.uga.edu
>Subject: Re: data step vs Proc sql
>To generalize a bit, the LIKE operator is valid in WHERE clauses (DATA
>step, PROCs SQL, SORT, etc.) and the CASE statement of SQL, but is not
>valid in the IF-THEN-ELSE construct of the DATA step. Can someone help
>me out with SELECT blocks of the DATA step?
>Mona alluded to using PRXMATCH in an earlier response, which has the
>advantage over LIKE in that it is more flexible & can be used in WHERE
>clauses *and* IF-THEN-ELSE. The disadvantage is that you have to learn
>the syntax of difficult-at-first-but-very-cool regular expressions.
>In a message dated 4/14/2006 12:32:15 PM Eastern Standard Time,
>swovcc@HOTMAIL.COM writes: On Fri, 14 Apr 2006 11:39:18 -0400, Ran S
>>I would like to know what is equivalent to Proc sql's 'like' operator
>>in data step?
>It is ... well ... like "LIKE" :-).
>The same operator is valid in the data step too:
>1 data _null_ ;
>2 set sashelp.class ;
>3 where upcase(name) like "JA%" ;
>4 put name = ;
>5 run ;
>NOTE: There were 3 observations read from the data set SASHELP.CLASS.
> WHERE UPCASE(name) like 'JA%';