Write and run SAS programs in your web browser

Syntax error

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Syntax error

Can any one help me to resolve or fix the following syntax error:

 

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, ), *, **, +, ',', -, '.',
/, <, <=, <>, =, >, >=, ?, AND, BETWEEN, CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS,
LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.
 
ERROR 76-322: Syntax error, statement will be ignored.
 
Thank you,

Accepted Solutions
Solution
‎08-19-2016 09:26 AM
Esteemed Advisor
Posts: 5,954

Re: Syntax error

So there are two separate errors.

The first is your use of the SQL AVG summary function. SQL summary functions need SQL expressions as arguments, and in SQL, variables must be separated by colons instead of spaces (as in a data step).

I also found that avg is only available for vertical use (one column over several records), for horizontal averaging (several columns in one record) you should use the mean() function.

So it should be

mean(Height,CMDS,CBSDL,CBSDS,CBSDRNharvest,SRNumber,SRMass,FSRYield,Groundbiomass,TBMass,Hindex,Dmcontent,BCarotene,PPD1w,PPD2w)

to make it syntactically correct.

The second error is the invocation of the macro %DialAnalFixModel, which is obviously not known to SAS at this stage. Make sure that a proper %include for the file where this macro is stored is in your program, or get the macro definition text and copy it into your program.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Esteemed Advisor
Posts: 5,954

Re: Syntax error

Well, it is a syntax error, meaning that the code is erroneous. We cannot help you without the code. Please post the whole log of the offending step.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 2

Re: Syntax error

proc sql;
create table import1 as
select I,J,ENTRY,avg(Height CMDS CBSDL CBSDS CBSDRNharvest SRNumber SRMass
FSRYield Groundbiomass TBMass Hindex Dmcontent BCarotene PPD1w PPD2w) as
avg_Y,AVGH
from import1
group by I,J,ENTRY;
title "Griffing model 1 method 4";
%DialAnalFixModel(NUM_P=6,method=4,Yvar=Height CMDS CBSDL CBSDS
CBSDRNharvest SRNumber SRMass FSRYield Groundbiomass TBMass Hindex
Dmcontent BCarotene PPD1w PPD2w,ENV=2,rep=3,dsn=import1);
run;
quit

results with error:

79 proc sql;
80 create table import1 as
81 select I,J,ENTRY,avg(Height CMDS CBSDL CBSDS CBSDRNharvest
SRNumber SRMass FSRYield Groundbiomass TBMass Hindex Dmcontent
____
22
76
81 ! BCarotene PPD1w PPD2w) as avg_Y,AVGH
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &,
(, ), *, **, +, ',', -, '.', /, <, <=, <>, =, >, >=, ?, AND,
BETWEEN, CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS,
LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||,
~, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
82 from import1
83 group by I,J,ENTRY;
NOTE: PROC SQL set option NOEXEC and will continue to check the
syntax of statements.
84 title "Griffing model 1 method 4";
WARNING: Apparent invocation of macro DIALANALFIXMODEL not resolved.
85 %DialAnalFixModel(NUM_P=6,method=4,Yvar=Height CMDS CBSDL
CBSDS CBSDRNharvest SRNumber SRMass FSRYield Groundbiomass
_
180
85 ! TBMass Hindex Dmcontent BCarotene PPD1w
PPD2w,ENV=2,rep=3,dsn=import1);
ERROR 180-322: Statement is not valid or it is used out of proper order.
86 run;
NOTE: PROC SQL statements are executed immediately; The RUN statement
has no effect.
87 quit
88
89 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.02 seconds



##- Please type your reply above this line. Simple formatting, no
attachments. -##
Solution
‎08-19-2016 09:26 AM
Esteemed Advisor
Posts: 5,954

Re: Syntax error

So there are two separate errors.

The first is your use of the SQL AVG summary function. SQL summary functions need SQL expressions as arguments, and in SQL, variables must be separated by colons instead of spaces (as in a data step).

I also found that avg is only available for vertical use (one column over several records), for horizontal averaging (several columns in one record) you should use the mean() function.

So it should be

mean(Height,CMDS,CBSDL,CBSDS,CBSDRNharvest,SRNumber,SRMass,FSRYield,Groundbiomass,TBMass,Hindex,Dmcontent,BCarotene,PPD1w,PPD2w)

to make it syntactically correct.

The second error is the invocation of the macro %DialAnalFixModel, which is obviously not known to SAS at this stage. Make sure that a proper %include for the file where this macro is stored is in your program, or get the macro definition text and copy it into your program.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Post a Question
Discussion Stats
  • 3 replies
  • 181 views
  • 0 likes
  • 2 in conversation