BookmarkSubscribeRSS Feed
rrmenon
Fluorite | Level 6

Hi I'm having trouble with the following code- specifically the subselect statements, any ideas on how to modify this?:



PROC SQL; CREATE TABLE WORK.QUERY_FOR_VVW_DWH_PTN AS SELECT t1.PlayerId, t1.FirstName, t1.LastName, t1.Email, t2.EndDate, t2.Most_Recent_Overall_Experience, t1.AdtLifetimeRange AS AdtLifetimeRange1, (SELECT t1.AdtLifetimeRange WHERE t2.EndDate <= intnx('month', today(), -6, 'e')) AS ADT6MoBack, (SELECT t1.AdtLifetimeRange WHERE t2.EndDate >= intnx('month', today(), -6, 'e')) AS ADT6MoForAS, FROM TDQT.vCXSurvey t2 INNER JOIN TDQT.vCXPlayer_SAS t1 ON (t2.PlayerId = t1.PlayerId); WHERE t2.EndDate <'20Mar2022'd; QUIT;



 

This is the error I get:

 

76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?,
AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH,
LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

41 FROM TDQT.vCXSurvey t2
42 INNER JOIN TDQT.vCXPlayer_SAS t1 ON (t2.PlayerId = t1.PlayerId);
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
43 WHERE t2.EndDate <'03/20/2022'
WARNING: This SAS global statement is not supported in PROC SQL. It has been ignored.
44 QUIT;
2 The SAS System Wednesday, March 29, 2023 09:06:00 AM

45
46
47
48 %LET _CLIENTTASKLABEL=;
49 %LET _CLIENTPROCESSFLOWNAME=;
50 %LET _CLIENTPROJECTPATH=;
51 %LET _CLIENTPROJECTPATHHOST=;
52 %LET _CLIENTPROJECTNAME=;
53 %LET _SASPROGRAMFILE=;
54 %LET _SASPROGRAMFILEHOST=;
55
56 ;*';*";*/;quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time

76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?,
AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH,
LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

41 FROM TDQT.vCXSurvey t2
42 INNER JOIN TDQT.vCXPlayer_SAS t1 ON (t2.PlayerId = t1.PlayerId);
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
43 WHERE t2.EndDate <'03/20/2022'
WARNING: This SAS global statement is not supported in PROC SQL. It has been ignored.
44 QUIT;
2 The SAS System Wednesday, March 29, 2023 09:06:00 AM

45
46
47
48 %LET _CLIENTTASKLABEL=;
49 %LET _CLIENTPROCESSFLOWNAME=;
50 %LET _CLIENTPROJECTPATH=;
51 %LET _CLIENTPROJECTPATHHOST=;
52 %LET _CLIENTPROJECTNAME=;
53 %LET _SASPROGRAMFILE=;
54 %LET _SASPROGRAMFILEHOST=;
55
56 ;*';*";*/;quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time



 

 

9 REPLIES 9
Reeza
Super User
I posted an answer on SO.
rrmenon
Fluorite | Level 6

Thanks I saw- for some reason not working still

Reeza
Super User

@rrmenon wrote:

Thanks I saw- for some reason not working still


You didn't provide any of the information requested either:

  • Original SQL language (this is not SAS SQL)
  • Full log that shows where the error occurred

 

Original answer:

 

  • Remove square brackets ]
  • Use INTNX() for date increments
  • Dates need to be in date. style - DDMMMYY ("20MAR2022"d)
  • There is no NOW() function in SAS, but there is TODAY() which returns today's date
  • Missing semicolon at end of query (before QUIT;)

An attempt at correcting your code, but not 100% sure as I don't know what type of SQL you're using:

PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_VVW_DWH_PTN AS 
   SELECT t1.PlayerId, 
          t1.FirstName, 
          t1.LastName, 
          t1.Email, 
          t2.EndDate, 
          t2.Most_Recent_Overall_Experience, 
          t1.AdtLifetimeRange AS AdtLifetimeRange1,
          (SELECT t1.AdtLifetimeRange WHERE t2.EndDate <= intnx('month', today(), -6, 'e')) AS ADT6MoBack,
          (SELECT t1.AdtLifetimeRange WHERE t2.EndDate >= intnx('month', today(), -6, 'e')) AS ADT6MoForAS,
 
      FROM TDQT.vCXSurvey t2
           INNER JOIN TDQT.vCXPlayer_SAS t1 ON (t2.PlayerId = t1.PlayerId);
    WHERE t2.EndDate <'20Mar2022'd;
QUIT;
PaigeMiller
Diamond | Level 26

@Reeza wrote:
I posted an answer on SO.

Many of us can't benefit from this, as we don't know what this means. Can you provide a link?

--
Paige Miller
rrmenon
Fluorite | Level 6

Thanks Reeza but I'm still getting the same error

rrmenon
Fluorite | Level 6

HI Reeza, the sub select statements do not have a From clasue, would you mind helmping me construct this?

PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_VVW_DWH_PTN AS 
   SELECT t1.PlayerId, 
          t1.FirstName, 
          t1.LastName, 
          t1.Email, 
          t2.EndDate, 
          t2.Most_Recent_Overall_Experience, 
          t1.AdtLifetimeRange AS AdtLifetimeRange1,
          (SELECT t1.AdtLifetimeRange WHERE t2.EndDate <= intnx('month', today(), -6, 'e')) AS ADT6MoBack,
          (SELECT t1.AdtLifetimeRange WHERE t2.EndDate >= intnx('month', today(), -6, 'e')) AS ADT6MoForAS,
 
      FROM TDQT.vCXSurvey t2
           INNER JOIN TDQT.vCXPlayer_SAS t1 ON (t2.PlayerId = t1.PlayerId);
    WHERE t2.EndDate <'20Mar2022'd;
QUIT;
Kurt_Bremser
Super User

You have a surplus comma before the FROM.

You also have a wrong semicolon before the WHERE.

Also please use a code box (as you did for the code) to post the log, so we can see where the ERROR markers are placed.

And post the whole log, from the start of the procedure to the QUIT;

s_lassen
Meteorite | Level 14

It's a bit hard to say where the error message comes from, but I think it is because you have a comma before FROM.

 

As for your "subselect" statements, they do not make sense at all. What are you trying to accomplish with those?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 586 views
  • 0 likes
  • 5 in conversation