<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: re: proc sql error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401604#M97475</link>
    <description>&lt;P&gt;also you may need to make sure the sub query doesn't return more than one records, guess it wont give you errors but it may get you unexpected results&lt;/P&gt;</description>
    <pubDate>Fri, 06 Oct 2017 04:22:20 GMT</pubDate>
    <dc:creator>ali_jooan</dc:creator>
    <dc:date>2017-10-06T04:22:20Z</dc:date>
    <item>
      <title>re: proc sql error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401539#M97437</link>
      <description>&lt;P&gt;&amp;nbsp;Hi...I can't seem to correct why I am receiving an error message.....I am wondering if anyone can see where the error is. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%LET StartDate = '2013-01-01 00:00:00.000';
%LET EndDate = '2017-12-31 23:59:59.999';

proc sql noprint;
	create table new as
		SELECT DISTINCT 
			S.StudentID, 
			S.LastName, 
			S.FirstName, 
			SP.MajorDegree, 
			SS.RegisterStatus, 
			S.DateEntered AS 'Matriculation Date'n, 
			S.WithdrawnDate, 
			(SELECT AdmissionDate FROM SQLDB.StudentDegree
				WHERE (StudentUID = S.StudentUID 
					AND MajorID1 = SP.MajorDegreeID) 
				ORDER BY GraduationDate DESC) AS AdmissionDate, 
			(SELECT GraduationDate FROM SQLDB.StudentDegree 
				WHERE (StudentUID = S.StudentUID 
					AND MajorID1 = SP.MajorDegreeID) 
				ORDER BY GraduationDate DESC) AS GraduationDate, 
			SS.EnrollmentStatus
	FROM  SQLDB.CAMS_StudentStatus_View SS
		INNER JOIN SQLDB.CAMS_Student_View S ON S.StudentUID = SS.StudentUID
		INNER JOIN SQLDB.CAMS_StudentProgram_View SP ON SP.StudentStatusID = SS.StudentStatusID
		INNER JOIN SQLDB.Programs PG ON S.ProgramsID = PG.ProgramsID
			WHERE S.DateEntered BETWEEN &amp;amp;StartDate AND &amp;amp;EndDate
				AND SP.MajorDegree ^= ''
			ORDER BY S.DateEntered, S.StudentID ASC;
quit;



Log output:

8         GOPTIONS ACCESSIBLE;
39         
40         %LET StartDate = '2013-01-01 00:00:00.000';
41         %LET EndDate = '2017-12-31 23:59:59.999';
42         
43         


44         proc sql noprint;
45         	create table new as
46         		SELECT DISTINCT
47         			S.StudentID,
48         			S.LastName,
49         			S.FirstName,
50         			SP.MajorDegree,
51         			SS.RegisterStatus,
52         			S.DateEntered AS 'Matriculation Date'n,
53         			S.WithdrawnDate,
54         			(SELECT AdmissionDate FROM SQLDB.StudentDegree
2                                                          The SAS System                            12:53 Thursday, October 5, 2017

55         				WHERE (StudentUID = S.StudentUID
56         					AND MajorID1 = SP.MajorDegreeID)
57         				ORDER BY GraduationDate DESC) AS AdmissionDate,
               _____
               22
               76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, ), *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN, 
              CONTAINS, EQ, EQT, EXCEPT, GE, GET, GROUP, GT, GTT, HAVING, IN, INTERSECT, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, 
              NOTIN, OR, OUTER, UNION, ^, ^=, |, ||, ~, ~=.  

ERROR 76-322: Syntax error, statement will be ignored.

58         			(SELECT GraduationDate FROM SQLDB.StudentDegree
59         				WHERE (StudentUID = S.StudentUID
60         					AND MajorID1 = SP.MajorDegreeID)
61         				ORDER BY GraduationDate DESC) AS GraduationDate,
62         			SS.EnrollmentStatus
63         	FROM  SQLDB.CAMS_StudentStatus_View SS
64         		INNER JOIN SQLDB.CAMS_Student_View S ON S.StudentUID = SS.StudentUID
65         		INNER JOIN SQLDB.CAMS_StudentProgram_View SP ON SP.StudentStatusID = SS.StudentStatusID
66         		INNER JOIN SQLDB.Programs PG ON S.ProgramsID = PG.ProgramsID
67         			WHERE S.DateEntered BETWEEN &amp;amp;StartDate AND &amp;amp;EndDate
68         				AND SP.MajorDegree ^= ''
69         			ORDER BY S.DateEntered, S.StudentID ASC;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
70         quit;&lt;/PRE&gt;
&lt;P&gt;Hi.....&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 22:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401539#M97437</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2017-10-05T22:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: re: proc sql error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401546#M97441</link>
      <description>&lt;P&gt;ORDER BY on subqueries don't make sense, I would start by removing them.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 22:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401546#M97441</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-05T22:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: re: proc sql error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401547#M97442</link>
      <description>&lt;P&gt;Have you verified that the subquery&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(SELECT AdmissionDate FROM SQLDB.StudentDegree55&lt;/P&gt;
&lt;P&gt;WHERE (StudentUID = S.StudentUID&lt;/P&gt;
&lt;P&gt;AND MajorID1 = SP.MajorDegreeID)&lt;/P&gt;
&lt;P&gt;ORDER BY GraduationDate DESC)&lt;/P&gt;
&lt;P&gt;returns only a single value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe the requirement for a subquery as a part of the select statement can return only a single value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 23:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401547#M97442</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-05T23:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: re: proc sql error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401564#M97446</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not saying there is anything wrong with your other responses, but I believe error message is caused by the way you assign a value to the macrovars, and the way you use them later.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let startdate='2013-01-01 00:00:00.000';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let enddate='2017-12-31 23:59:59:999';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Later on you have the expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp; WHERE S.DateEntered BETWEEN &amp;amp;StartDate AND &amp;amp;EndDate&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if DateEntered is a character variable, then ignore my comments.&amp;nbsp;&amp;nbsp;But if DateEntered is a sas datetime variables, then use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET StartDate = 2013-01-01 00:00:00.000;
%LET EndDate = 2017-12-31 23:59:59.999;

proc sql ...

    WHERE S.DateEntered BETWEEN "&amp;amp;StartDate"dt AND "&amp;amp;EndDate"dt
	...
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This approach allows you to properly use macrovars to specify a datetime literal.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;In the %LET statement, don't use any quotes.&lt;/LI&gt;
&lt;LI&gt;Refer to those macrovars&amp;nbsp; within double quotes and end with the literal type (dt for datetime).&amp;nbsp; Double quotes allows the macroprocessor to resolve the STARTDATE and ENDATE text in the executable prior to datetime conversion.&amp;nbsp; Single quotes would preserve the text '&amp;amp;startdate'.&amp;nbsp; That's probably why you put the single quotes in the %let statement.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 06 Oct 2017 00:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401564#M97446</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-06T00:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: re: proc sql error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401603#M97474</link>
      <description>&lt;P&gt;I think order by will not work in the nested Select statements. Try removing it and run.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 04:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401603#M97474</guid>
      <dc:creator>ali_jooan</dc:creator>
      <dc:date>2017-10-06T04:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: re: proc sql error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401604#M97475</link>
      <description>&lt;P&gt;also you may need to make sure the sub query doesn't return more than one records, guess it wont give you errors but it may get you unexpected results&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 04:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/401604#M97475</guid>
      <dc:creator>ali_jooan</dc:creator>
      <dc:date>2017-10-06T04:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: re: proc sql error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/402097#M97610</link>
      <description>&lt;P&gt;Hi Ballardw.....thank you for suggestion....I did remove the order by in the sub query with the select statement and receive a different error message which most likely was due to not being able to return a single value. I ended up breaking the queries into separate proc sql procedures and then joining the query results together. Thanks once again....greatly appreciated your help.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 16:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/402097#M97610</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2017-10-07T16:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: re: proc sql error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/402098#M97611</link>
      <description>&lt;P&gt;Hi Mkeintz.....thanks for your suggestion and explanation....it worked.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 16:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-proc-sql-error/m-p/402098#M97611</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2017-10-07T16:57:47Z</dc:date>
    </item>
  </channel>
</rss>

