DATA Step, Macro, Functions and more

ERROR 22-322 - PLEASE HELP!!!!!!

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

ERROR 22-322 - PLEASE HELP!!!!!!

Hi!  I keep getting the ERROR 22-322 in the below program.  Please advise what to do.  I've run it a hundred times already.  It doesnt appear to be the parentheses or a misspelling anywhere.  And the codes are listed properly so I'm not sure what it could be.  I appreciate any help on this. Thank you!

 

                                                                            
4144           PROC SQL;                                                    
4145              CREATE TABLE CLAIM1.DATA AS                               
4146              SELECT DISTINCT                                           
4147                A.*,                                                    
4148                B.EPBEGINDATE,                                          
4149                B.EPENDDATE,                                            
9                                                          The SAS System   
                                                                            
4150                B.MAINJTCODE                                            
4151              FROM EPCLAIM1.DATA AS A, SELECT1.DATA AS B                
4152              WHERE (A.BENEID = B.BENEID)                               
4153                   AND (                                                
4154                    (/* OCCURRED DURING SURGERY STAY */         

4155                      A.CLMBEGINDATE >= B.EPBEGINDATE                      
4156                          AND A.CLMENDDATE <= B.EPENDDATE)                 
4157                      OR (/* ORTHOPEDIC SPECIALIST */                      
4158                        A.SPECCODE IN &SPECLIST )                          
4159                      OR (/* PHYSICAL THERAPY */                           
4160                         (A.SPECCODE = '65'                                
4161                            OR A.CPTCODE IN ('97001','97002','97750','97751'
4162                                             '97752','97753','97754','97755'
4163                                             '97799')                      
4164                               OR A.CPTCODE BETWEEN ('97010' AND '97546')  
4165                                ) /** CLOSES OFF LOGIC TO IDENTIFY PT **/  
                                    _                                          
                                    _                                          
                                    _                                          
                                    22                                         
                                    22                                         
                                    22                                         
4166                      AND A.SPECCODE <> 'A3') /** NOT OCCUPATIONAL THERAPY *
                          ___            __                                    
                          ___            __                                    
                          ___            __                                    
                          202            79                                    
                          202            79                                    
                          202            79                                    
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /,
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /,
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /,
ERROR 202-322: The option or parameter is not recognized and will be ignored.  
ERROR 202-322: The option or parameter is not recognized and will be ignored.  
ERROR 202-322: The option or parameter is not recognized and will be ignored.  
                                                                               
ERROR 79-322: Expecting a ).                                                   
ERROR 79-322: Expecting a ).                                                   
ERROR 79-322: Expecting a ).                                                   
                                                                               
4167                       /** CLOSES OFF COMPLETE PT LOGIC **/                
4168                   OR (/** MUSCULOSKELETAL DIAGNOSIS CODE **/              
4169                     (SUBSTR(A.DIAGCODE,1,1)="M")  )                       
4170                 OR ( /* AFTERCARE CODE AFTER ORTHO SURG */                
4171                   A.CLMBEGINDATE > B.EPBEGINDATE                          
4172                AND A.DIAGCODE IN ('Z471','Z472','Z473','Z4731',           
4173                                               'Z4732','Z4733') OR         
4174                     A.DIAGCODE BETWEEN ('Z966' AND 'Z96669')              
4175                      ) /* CLOSES OFF DIAGNOSIS CODES */                   
                          _                                                    
                          _                                                    
                          _                                                    
                          22                                                   
                          22                                                   
                          22                                                   
                          76                                                   
                          76                                                   
                          76                                                   
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /,
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /,                       

ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /,
                                                                               
ERROR 76-322: Syntax error, statement will be ignored.                         
ERROR 76-322: Syntax error, statement will be ignored.                         
ERROR 76-322: Syntax error, statement will be ignored.                         
                                                                               
4176                      ) /* CLOSES OFF AFTERCARE LOGIC */                   
4177                 );                                                        
NOTE: The "<>" operator is interpreted as "not equals".                        
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statem
4178             QUIT;                                                         
NOTE: The SAS System stopped processing this step because of errors.           
NOTE: The PROCEDURE SQL used 0.01 CPU seconds and 18010K.                                                                                         


Accepted Solutions
Solution
‎03-18-2017 10:44 PM
Contributor
Posts: 72

Re: ERROR 22-322 - PLEASE HELP!!!!!!

Hello Essdee,

 

I took the code that you posted a few hours back this morning (NZT) and I think I have fixed the un-matched parentheses and the un-closed comment containing the phrase "NOT OCCUPATIONAL THERAPY".

 

As there are quite a few ANDs and ORs and a bit of nesting, I have laid out the code in a way that makes sense to me when I read it. I emphasise that this layout suits me, I am not prescribing it as the only way to do such things.

 

Aside from the parentheses and the comment I am not aware that I have changed the content of the code you posted. However, please use this version below at your caution, I cannot accept any responsiblilty for errors, omissions or losses. This code runs without WARNINGs or ERRORs and SAS successfully creates the dataset CLAIM1.DATA with a note about how Proc SQL interpreted the use of the "<>" in the code.

 

I made up some fake datasets as input which is why the number of rows and columns returned in my snippet below will likely differ from your real life data.

 

NOTE: The "<>" operator is interpreted as "not equals".
NOTE: Table CLAIM1.DATA created, with 1 rows and 9 columns.

 

I suggest that you try this new Proc SQL step pasted below as a test ONLY and then compare it to your original version.

 

Proc SQL; 
 Create Table CLAIM1.DATA As                                   
 Select DISTINCT
        A.*,
        B.EPBEGINDATE,
        B.EPENDDATE,
        B.MAINJTCODE
From    EPCLAIM1.DATA AS A,
        SELECT1.DATA  AS B
Where   (A.BENEID = B.BENEID)
        AND (
                (/* OCCURRED DURING SURGERY STAY */
                A.CLMBEGINDATE  >= B.EPBEGINDATE
                AND
                A.CLMENDDATE    <= B.EPENDDATE
                )
            OR  (/* ORTHOPEDIC SPECIALIST */
                A.SPECCODE IN &SPECLIST)
            OR  (/* PHYSICAL THERAPY */
                (A.SPECCODE = '65' OR A.CPTCODE IN ('97001','97002','97750','97751','97752','97753','97754','97755', '97799')
                OR
                (A.CPTCODE BETWEEN '97010' AND '97546')
                ) /** CLOSES OFF LOGIC TO IDENTIFY PT **/
                AND
                A.SPECCODE <> 'A3'
                ) /** NOT OCCUPATIONAL THERAPY **/
            /** CLOSES OFF COMPLETE PT LOGIC **/

        OR  (/** MUSCULOSKELETAL DIAGNOSIS CODE **/
            (SUBSTR(A.DIAGCODE,1,1)="M")
            )
        OR  ( /* AFTERCARE CODE AFTER ORTHO SURG */
            A.CLMBEGINDATE > B.EPBEGINDATE
            AND
            A.DIAGCODE IN ('Z471','Z472','Z473','Z4731', 'Z4732','Z4733') OR (A.DIAGCODE BETWEEN 'Z966' AND 'Z96669')
            ) /* CLOSES OFF DIAGNOSIS CODES */
            );
Quit;

Best of luck, I think you're almost home and dry now.Smiley Wink

 

Downunder Dave

 

 

View solution in original post


All Replies
SAS Super FREQ
Posts: 3,753

Re: ERROR 22-322 - PLEASE HELP!!!!!!

I think there are missing commas in the IN list:

CPTCODE IN ('97001','97002','97750','97751'   /* <== NO COMMA */
4162                                             '97752','97753','97754','97755' /* <== NO COMMA HERE EITHER */
4163                                             '97799')  

Contributor
Posts: 46

Re: ERROR 22-322 - PLEASE HELP!!!!!!

There are commas on the end of those, it's just not showing in the log unless I do F11, but the commas there.

Super User
Posts: 19,817

Re: ERROR 22-322 - PLEASE HELP!!!!!!

Check the BETWEEN condition as well, not sure if the extra parentheses here will help. 

 

To debug code like this, block out your WHERE conditions iteratively and add them back to see where the issue is originating. 

Super User
Posts: 11,343

Re: ERROR 22-322 - PLEASE HELP!!!!!!

Please post code and logs using the codebox opened using the {i} icon on the menu.

The main message area reformats text pasted from the log. Meaning things like the _ that appears in error messages does not appear where it should to indicate the actual error location.

 

The error message seems to imply the first error causes SAS to want to do a numeric calculation

 

Try changing your /**   **/ comments to /*  */

 

 

Contributor
Posts: 46

Re: ERROR 22-322 - PLEASE HELP!!!!!!

4144           PROC SQL;                                                        
4145              CREATE TABLE CLAIM1.DATA AS                                   
4146              SELECT DISTINCT                                               
4147                A.*,                                                        
4148                B.EPBEGINDATE,                                              
4149                B.EPENDDATE,                                                
9                                                          The SAS System       
                                                                                
4150                B.MAINJTCODE                                                
4151              FROM EPCLAIM1.DATA AS A, SELECT1.DATA AS B                    
4152              WHERE (A.BENEID = B.BENEID)                                   
4153                   AND (                                                    
4154                    (/* OCCURRED DURING SURGERY STAY */                     
4155                      A.CLMBEGINDATE >= B.EPBEGINDATE                       
4156                          AND A.CLMENDDATE <= B.EPENDDATE)                  
4157                      OR (/* ORTHOPEDIC SPECIALIST */                       
4158                        A.SPECCODE IN &SPECLIST )                           
4159                      OR (/* PHYSICAL THERAPY */                            
4160                         (A.SPECCODE = '65'                                 
4161                            OR A.CPTCODE IN ('97001','97002','97750','97751'
4162                                             '97752','97753','97754','97755'
4163                                             '97799')                       
4164                               OR A.CPTCODE BETWEEN ('97010' AND '97546')   
4165                                ) /** CLOSES OFF LOGIC TO IDENTIFY PT **/   
                                    _                                           
                                    _                                           
                                    _                                           
                                    22                                          
                                    22                                          
                                    22                                          
4166                      AND A.SPECCODE <> 'A3') /** NOT OCCUPATIONAL THERAPY *
                          ___            __                                     
                          ___            __                                     
                          ___            __                                     
                          202            79                                     
                          202            79                                     
                          202            79                                     
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /, 
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /, 
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /, 
ERROR 202-322: The option or parameter is not recognized and will be ignored.   
ERROR 202-322: The option or parameter is not recognized and will be ignored.   
ERROR 202-322: The option or parameter is not recognized and will be ignored.   
                                                                                
ERROR 79-322: Expecting a ).                                                    
ERROR 79-322: Expecting a ).                                                    
ERROR 79-322: Expecting a ).                                                    
                                                                                
4167                       /** CLOSES OFF COMPLETE PT LOGIC **/                 
4168                   OR (/** MUSCULOSKELETAL DIAGNOSIS CODE **/               
4169                     (SUBSTR(A.DIAGCODE,1,1)="M")  )                        
4170                 OR ( /* AFTERCARE CODE AFTER ORTHO SURG */                 
4171                   A.CLMBEGINDATE > B.EPBEGINDATE                           
4172                AND A.DIAGCODE IN ('Z471','Z472','Z473','Z4731',            
4173                                               'Z4732','Z4733') OR          
4174                     A.DIAGCODE BETWEEN ('Z966' AND 'Z96669')               
4175                      ) /* CLOSES OFF DIAGNOSIS CODES */                    
                          _                                                     
                          _                                                     
                          _                                                     
                          22                                                    
                          22                                                    
                          22                                                    
                          76                                                    
                          76                                                    
                          76                                                    
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /, 
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /,      
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, -, /, 
                                                                                
ERROR 76-322: Syntax error, statement will be ignored.                          
ERROR 76-322: Syntax error, statement will be ignored.                          
ERROR 76-322: Syntax error, statement will be ignored.                          
                                                                                
4176                      ) /* CLOSES OFF AFTERCARE LOGIC */                    
4177                 );                                                         
NOTE: The "<>" operator is interpreted as "not equals".                         
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statem
4178             QUIT;                                                                                                                                          
Contributor
Posts: 46

Re: ERROR 22-322 - PLEASE HELP!!!!!!

Thank you that works great!  Yes, I've had one asterisk, I've had two asterisks, just trying to figure it out, but its nothign to do with that...

PROC Star
Posts: 7,474

Re: ERROR 22-322 - PLEASE HELP!!!!!!

here is at least one line to fix:

4166               **       AND A.SPECCODE <> 'A3') /** NOT OCCUPATIONAL THERAPY *

should be:

4166               **       AND A.SPECCODE <> 'A3') /** NOT OCCUPATIONAL THERAPY */

i.e., you end the comment only with * rather than */

 

Fix it, rerun the code and, if it still doesn't run, repost the new log

 

Art, CEO, AnalystFinder.com

 

 

Contributor
Posts: 46

Re: ERROR 22-322 - PLEASE HELP!!!!!!

Theres a slash, it just doesnt show. But i have it in my program.

Contributor
Posts: 72

Re: ERROR 22-322 - PLEASE HELP!!!!!!

Hi Essdee,

 

I think that the problem is unbalanced pairs of parentheses.

 

I count 14 opening parentheses <(> and 15 closing parentheses <)>.

 

My first act would be to match each opening parenthesis with its closing partner. Whilst I applaud comments in SAS code, I think you might want to get rid of your comments for the moment and put them back when you have sorted out the syntax problem.

 

The IN operator that uses a mixture of spaces and commas to separate the arguments is valid syntax, even though I would stick to one or the other of the separators to keep things neat and tidy. The code below produces output that I expected:

 

Proc SQL;
 Select *
 From   SASHELP.CLASS
 Where  Name In ("Alfred", "Carol", "Henry" "James" "John")
;
Quit;

 

I hope that this helps.

 

Downunder Dave

Contributor
Posts: 72

Re: ERROR 22-322 - PLEASE HELP!!!!!!

Hi Essdee,

 

I think I now have the solution for you.

 

There are two issues for you to address to get valid syntax:

1) The last-but one closing parenthesis needs to be removed. This is the one that appears in your code as follows:

) /* CLOSES OFF AFTERCARE LOGIC */ 

Just delete the whole line containing the closing parenthesis and the comment from your code. You can put the comment back later when you have this beast roaring.

 

2) There are two BETWEEN operators in use in the code which need to be amended. A BETWEEN operator does not have its <from> and <to> arguments enclosed in parentheses. Consequently this snippet is invalid:

A.DIAGCODE BETWEEN ('Z966' AND 'Z96669')

whereas this snippet is valid:

(A.DIAGCODE BETWEEN 'Z966' AND 'Z96669')

It is up to you whether you wrap the whole thing up in parentheses as shown above and sometimes I do this for clarity for the humans who get to read our code Smiley Wink

 

Remember that there are TWO of these BETWEEN expressions to be fixed in your code.

 

When I fixed both BETWEENs and the dangling closing parenthesis in the code that you posted, SAS reported valid syntax.

 

I hope that this helps and good luck.

 

Downunder Dave.

PROC Star
Posts: 7,474

Re: ERROR 22-322 - PLEASE HELP!!!!!!

In case I wasn't sufficiently clear earlier, before you go about removing or adding parentheses

CLOSE YOUR ONE UN-CLOSED COMMENT

before doing anything else

 

If there are other errors, they should be easy to identify in the log

 

Art, CEO, AnalystFinder.com

 

Super User
Super User
Posts: 7,059

Re: ERROR 22-322 - PLEASE HELP!!!!!!

I want to double emphasize @DaveShea's point about the BETWEEN keyword.

The syntax for use is 

sql-expression <NOT> BETWEEN sql-expression AND sql-expression

if you write code like

 A.CPTCODE BETWEEN ('97010' AND '97546')

This is the same as if you had coded:

A.CPTCODE BETWEEN 1

You only have two sql expressions and you do not have the required AND keyword.

Contributor
Posts: 46

Re: ERROR 22-322 - PLEASE HELP!!!!!!

[ Edited ]
    PROC SQL;                                                           
       CREATE TABLE CLAIM1.DATA AS                                      
       SELECT DISTINCT                                                  
         A.*,                                                           
         B.EPBEGINDATE,                                                 
         B.EPENDDATE,                                                   
         B.MAINJTCODE                                                   
       FROM EPCLAIM1.DATA AS A, SELECT1.DATA AS B                       
       WHERE (A.BENEID = B.BENEID)                                      
            AND (                                                       
             (/* OCCURRED DURING SURGERY STAY */                        
               A.CLMBEGINDATE >= B.EPBEGINDATE                          
                   AND A.CLMENDDATE <= B.EPENDDATE)                     
               OR (/* ORTHOPEDIC SPECIALIST */                          
                 A.SPECCODE IN &SPECLIST )                              
               OR (/* PHYSICAL THERAPY */                               
                  (A.SPECCODE = '65'                                    
                     OR A.CPTCODE IN ('97001','97002','97750','97751',  
                                      '97752','97753','97754','97755',  
                                      '97799')                          
                        OR (A.CPTCODE BETWEEN '97010' AND '97546')      
                          /** CLOSES OFF LOGIC TO IDENTIFY PT **/       
            AND (A.SPECCODE <> 'A3') /** NOT OCCUPATIONAL THERAPY **/   
                 )/** CLOSES OFF COMPLETE PT LOGIC **/                  
            OR (/** MUSCULOSKELETAL DIAGNOSIS CODE **/                  
              (SUBSTR(A.DIAGCODE,1,1)="M")  )                           
         OR ( /* AFTERCARE CODE AFTER ORTHO SURG */                    
           A.CLMBEGINDATE > B.EPBEGINDATE                              
        AND (SUBSTR(A.DIAGCODE,1,4) IN ('Z471','Z472','Z473','Z4731',  
                                    'Z4732','Z4733') OR                
           (SUBSTR(A.DIAGCODE,1,4) BETWEEN 'Z966' AND 'Z96669')        
               /* CLOSES OFF DIAGNOSIS CODES */                        
               /* CLOSES OFF AFTERCARE LOGIC */                        
         )                                                             
         );                                                            
     QUIT;                                                             
                                                                       

Here is the error I get after running the above code:

4174                   (SUBSTR(A.DIAGCODE,1,4) BETWEEN 'Z966' AND 'Z96669')    
4175                       /* CLOSES OFF DIAGNOSIS CODES */                    
4176                       /* CLOSES OFF AFTERCARE LOGIC */                    
4177                 )                                                         
4178                 );                                                        
                      _                                                        
                      _                                                        
                      _                                                        
                      22                                                       
                      22                                                       
                      22                                                       
                      76                                                       
                      76                                                       
                      76                                                       
NOTE: The "<>" operator is interpreted as "not equals".                        
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, ), *, **,
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, ), *, **,
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, ), *, **,
              CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LT
              CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LT
              CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LT
                                                                               
ERROR 76-322: Syntax error, statement will be ignored.                         
ERROR 76-322: Syntax error, statement will be ignored.                         
ERROR 76-322: Syntax error, statement will be ignored.                   

                                                                               
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statem
4179             QUIT;                                                         
NOTE: The SAS System stopped processing this step because of errors.           
NOTE: The PROCEDURE SQL used 0.00 CPU seconds and 18010K.                      
                                                                                      

 

PROC Star
Posts: 7,474

Re: ERROR 22-322 - PLEASE HELP!!!!!!

I didn't check your full code, but aren't you missing a parenthesis at:

 

A.SPECCODE IN &SPECLIST )                              

Shouldn't it be:

 

A.SPECCODE IN (&SPECLIST )                              

However, not knowing what's in that macro variable, can't be sure that is one of your problems.

 

Art, CEO, AnalystFinder.com

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 29 replies
  • 3298 views
  • 0 likes
  • 7 in conversation