title: If/Then/Else in SAS Not Working
body: <p>Struggling to get this If/Then/Else statement not working. I have two columns: Variable and Value. Variable has the name of the variable and Value has all the potential codes that could be associated with that Variable. </p>
  
  <p>Example:</p>
  
  <pre><code>Variable     Value
  Gender         F
  Gender         M
  </code></pre>
  
  <p>I want to create a field called "Flag" and if the value isn't among the list of values, it should flag that field; otherwise, leave that field blank</p>
  
  <pre><code>data Want;
  length 
  Variable $40.
  Value $40.
  Flag $8.;
  set Have (keep = Variable Value);
  if (Variable = 'Gender' and Value ^= 'M') then Flag = 'UnkCode'; else Flag="";
  if (Variable = 'Gender' and Value ^= 'F') then Flag = 'UnkCode'; else  Flag="";
  if (Variable = 'Gender' and Value ^= 'O') then Flag = 'UnkCode'; else Flag="";
  if (Variable = 'Gender' and Value ^= 'U') then Flag = 'UnkCode'; else Flag="";
  run;
  quit;
  </code></pre>
  
  <p>The dataset I'm using has only has two values for Gender: F and M. For whatever reason, the flag field in both lines has "UnkCode"</p>
  
  <p>Any idea what I'm doing wrong? </p>