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";
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"
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?
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
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.
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";
OHHHH - sorry blonde roots.. I see what you are saying.. let me try that! Hang on!
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.
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"
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!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.