| Date: | Thu, 8 Nov 2007 13:51:08 -0600 |
| Reply-To: | Kevin Morgan <kmorgan@GRAINSCANADA.GC.CA> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Kevin Morgan <kmorgan@GRAINSCANADA.GC.CA> |
| Subject: | Re: SQL newbie question |
|
| In-Reply-To: | A<OF8628688C.296A4517-ON8625738D.00543A0A-8625738D.0054B07D@fd9ns01.okladot.state.ok.us> |
| Content-Type: | text/plain; charset="us-ascii" |
Hi:
The ordering of your clauses are incorrect, clauses always follow the
select statement and the order is
1) Select
2) From
3) Where
4) group by
5) Having
6) order by
You cannot have a select follow a where clause unless you are nesting
your select statement to filter into the where clause.
For example:
proc sql;
create view PropItem as
select *
from pls.PROPITEM as prop full Join pls.ITEMLIST as item on
Prop.propitem=Item.item
where contid="070403" and idesc in
(Select DISTINCT item.idescr from
pls.ITEMLIST WHERE IDESCR contains...) ;
quit;
Finally if you are dealing with tables with many columns and are only
outputting a small table I find it helps to declare which columns you
want in your select statement rather than using select * and then a
data step keep option.
Hope that helps.
Kevin
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Masuod Pajoh
Sent: Thursday, November 08, 2007 9:25 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: SQL newbie question
proc sql;
create view PropItem as
select *
from pls.PROPITEM as prop
where contid="070403"
select item.idescr item.descrl
from pls.ITEMLIST as item
where prop.propitem=item.item
;
quit;
returns:
136 proc sql;
137 select *
138 from pls.PROPITEM as prop
139 where contid="070403"
140 select item.idescr item.descrl
-
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *,
**, +, -, /, <, <=, <>, =, >, >=, AND, EQ, EQT, EXCEPT, GE, GET, GROUP,
GT,
GTT, HAVING, INTERSECT, LE, LET, LT, LTT, NE, NET, OR,
ORDER, UNION, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
What am I missing?
|