Desktop productivity for business analysts and programmers

Missing parentheses?

Reply
Frequent Contributor
Posts: 104

Missing parentheses?

       DATA HEDIS.CHEMFY17;
25         SET CHEM.a_chem_fy17_d171103 (KEEP=EDIPN RLOINC RLOINCN LABRNCID LABRID FMONTH FYEAR) /*AK FY17 - COMES FROM SAME FILE AS
25       !  PHARMACY FILES SO LEAVE AS RX.*/
26             CHEM.w_chem_fy17_d171103 (KEEP=EDIPN RLOINC RLOINCN LABRNCID LABRID FMONTH FYEAR);
27         KEY = (LABRNCID || LABRID);
28         WHERE FMONTH GE '05' AND RLOINC IN &LOINCG OR RLOINC IN &LOINCH);
                                              _
                                              22
                                              76
WARNING: Apparent symbolic reference LOINCG not resolved.
WARNING: Apparent symbolic reference LOINCH not resolved.
ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: (, :.  

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

29         RUN;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      27:8    27:20   
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set HEDIS.CHEMFY17 may be incomplete.  When this step was stopped there were 0 observations and 8 variables.
WARNING: Data set HEDIS.CHEMFY17 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      
PROC Star
Posts: 1,564

Re: Missing parentheses?

If my eyesight is reasonable, i think it's here

 

WHERE (FMONTH GE '05' AND RLOINC IN (&LOINCG)) OR (RLOINC IN (&LOINCH));

Super User
Super User
Posts: 7,932

Re: Missing parentheses?

I would be more worried about the macro variables not being defined. 

There problem that caused that is probably somewhere earlier in the program.

 

It is possible if the macro variables are defined as that line of code expected then the WHERE clause will work.  Although the logic looks sketchy since it has both AND and OR and no grouping.  Are you sure SAS is going to know how to do what you want?

Super User
Posts: 6,628

Re: Missing parentheses?

A few items here ...

 

First, the logic appears to be incorrect, even if there were no errors.  AND gets applied before OR.  So even a working program would evaluate as if you had parentheses here:

 

WHERE (FMONTH GE '05' AND RLOINC IN &LOINCG) OR (RLOINC IN &LOINCH);

 

Actually, your original WHERE statement contains one right-parenthesis but no left-parenthesis, so it's difficult to understand the logic that you intended here.

 

Second, there are the WARNING messages.  You can't ignore them.  They tell you that you refer to macro variables &LOINCG and &LOINCH, but those macro variables don't exist.  So you will need to create them before you can use this program.

 

Finally, there's the ERROR message.  It's difficult to tell if you should even worry about that one.  The key issue:  If you had properly created &LOINCG and &LOINCH, would they already contain parentheses?  If not, you would need to add them:

 

(&LOINCG)

(&LOINCH)

 

The IN operator expects to see parentheses around the list of values.

Super User
Posts: 13,297

Re: Missing parentheses?

Just be a bit pedantic the IN operator in a data step requires the values to search inside ( ).

 

if x in ( 1 2 3) then ...

or

If y in ('a' 'b' 'c') then ...

 

which is why folks are pointing at your code using IN  and why: ERROR 22-322: Syntax error, expecting one of the following: (

 

I would also be a tad concerned over this line of code:

27         KEY = (LABRNCID || LABRID);

Since SAS has this:

 

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      27:8    27:20 

If you expect Key to match some other value implied conversions with the || concatenation operator is a likely failure point as the conversion to text will use a BEST format that may well have differing numbers of spaces in the middle of the value and decimals can be displayed in undesirable fashions. Given that the variables end in ID I would suspect them of being ID variables of some sort and such usually should not be numeric unless you intend to do arithmetic, which is seldom a good idea.

 

Ask a Question
Discussion stats
  • 4 replies
  • 135 views
  • 0 likes
  • 5 in conversation