BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Blndbrm727
Calcite | Level 5

Hello All-

 

I am getting this error. I have retyped that portion of the code and it did not work. Thank you in advance! 

Code: 
If Fent=1 or Opiate=1 or Methd=1 or Oxy=1 or AMP=1 or MDMA=1 or COC= or Metam=1 or THC= or PCP=1 or Benzo=1 or Barb=1
or Ethn=1 or TCA=1 then Anydrug_Positive="YES";
else Anydrug_Positive="NO";

Log:
867  If Fent=1 or Opiate=1 or Methd=1 or Oxy=1 or AMP=1 or MDMA=1 or COC= or Metam=1 or THC= or
                                                                             -----
---
                                                                             22                 22
867! PCP=1 or Benzo=1 or Barb=1
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, ;, <,
              <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR,
              [, ^=, {, |, ||, ~=.

868  or Ethn=1 or TCA=1 then Anydrug_Positive="YES";
869  else Anydrug_Positive="NO";

 

1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

most of the time when you see those ----- marks on the error statement in the log the problem is just before those marks.

 

So if PCP=1 and has underlines under it the problem would be the element being evaluated prior to that.  In your if statement that looks like THC is still null in your statement when SAS executes.

 

If you are putting THC=1 and that is the error maybe THC has a type of character where you would need to put THC="1"

View solution in original post

9 REPLIES 9
Cynthia_sas
SAS Super FREQ
Hi:
Are you sure that ALL your conditions are correct? For example, what do you hope to find with
COC= and THC=
should it be COC=1 and THC=1???

What are the values of COC and THC that you are testing for?

Typically in an OR condition, you have something like this:
IF var1=value1 OR var2=value2 OR var3=value3 then newvar = newvalue;
So it seems to me that there is something wrong with how you have constructed the OR conditions for COC and THC variables.

Cynthia
Blndbrm727
Calcite | Level 5

These are all drugs. COC= cocaine. THC= marijuana. All are substances on toxicology panels and are coded in my database as 0=negative 1=positive 2=not tested. In this particular command I am trying to code for any one of the substances being a "1" or positive. I have done the same for "0" or being any drug negative and it worked perfectly. 

 

What is interesting is each time I retype the code for the variable SAS gets hung up on ( at first it was METAM (methamphetamine) SAS moves to a different variable.  It is now hung up on PCP. I Have retyped the PCP variable code 3 times but it is not moving off it. I am perplexed. Would (   ) around the code help?

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

you must supply a value for this

 COC= or Metam=1 or THC=

COC=

THC=

 

that is what the error is telling you.

try replacing the above with

COC=1 or Metam=1 or THC=1

 

Blndbrm727
Calcite | Level 5
My code has all values assigned:
If Fent=1 or Opiate=1 or Methd=1 or Oxy=1 or AMP=1 or MDMA=1 or COC=1 or METAM=1 or THC=1 or PCP=1 or Benzo=1 or Barb=1 or Ethn=1 or TCA=1 then Anydrug_Positive="YES";
else Anydrug_Positive="NO";

But the log is not showing those values assigned:
1458  If Fent=1 or Opiate=1 or Methd=1 or Oxy=1 or AMP=1 or MDMA=1 or COC=1 or Metam=1 or THC= or
1458! PCP=1 or Benzo=1 or Barb=1 or Ethn=1 or TCA=1 then Anydrug_Positive="YES";
      ---
      22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, ;, <,
              <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR,
              [, ^=, {, |, ||, ~=.

1459  else Anydrug_Positive="NO";

Can anyone explain this> I have retyped the code the code manually and yet the log keeps doing this. 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

the error still points to the THC=

 

your THC value in the if statement doesn't match what SAS sees when it evaluates THC.

 

just for kick try making 2 if statements 

If Fent=1 or Opiate=1 or Methd=1 or Oxy=1 or AMP=1 or MDMA=1 or COC=1 or METAM=1 then Anydrug_Positive="YES";

else if THC=1 or PCP=1 or Benzo=1 or Barb=1 or Ethn=1 or TCA=1 then Anydrug_Positive="YES";
else Anydrug_Positive="NO";

Blndbrm727
Calcite | Level 5

OHHHH - sorry blonde roots.. I see what you are saying.. let me try that! Hang on! 

Blndbrm727
Calcite | Level 5
If Fent=1 or Opiate=1 or Methd=1 or Oxy=1 or MP=1 or MDMA=1 or COC=1 or
 METAM=1 or THC=1 or PCP=1 or Benzo=1 or 
Barb=1 or Ethn=1 or TCA=1 then Anydrug_Positive="YES";
else Anydrug_Positive="NO";

The above is my code. So every drug has a value of "1" assigned and I am still getting the error on PCP.
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

most of the time when you see those ----- marks on the error statement in the log the problem is just before those marks.

 

So if PCP=1 and has underlines under it the problem would be the element being evaluated prior to that.  In your if statement that looks like THC is still null in your statement when SAS executes.

 

If you are putting THC=1 and that is the error maybe THC has a type of character where you would need to put THC="1"

Blndbrm727
Calcite | Level 5

SUCCESS!! THANK YOU VDD! I am working on a first of its kind biosurveillance system in the US for the CDC. and Giving my first report on Wednesday So trying to run all this data over the weekend. I appreciate everyone's help on this. I will probably be back on here again as I learn all the ins and outs of SAS! 

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
  • 5100 views
  • 0 likes
  • 3 in conversation