title: how to write sql query from sas based on if then statements
body: <p>I don't really have any advanced sql knowledge on how to phrase if/then statements in sql (whether to use case, for example) and/or formatting variables in the same query so I was wondering if someone could help with this sas code and phrasing it in the correct format into sql:</p>
  
  <pre><code>data convert_code;
  
  format date1 date 2 mmddyy8. code $4.;
  
  set userid.code; (this table is pulled from oracle)
  
  if ID='X' then P='A'; else P='B';
  
  If CAT in ('1','2','3') then CAT_group='ONE'; else CAT_GROUP='TWO';
  
  if CAT_2 &gt; '0' and CAT_2A &gt;='1' then d=1; else d=0;
  
  date1=datepart(date1);
  
  date2=datepart(date2);
  
  if code='3' and type_code in ('A','B','C') THEN DO;
  
  if P_CODE in ('1','2','3') then P='1';
  
  if P_CODE in ('4','5','6') then P='2';
  
  end;
  
  if code='4' and e_code in ('A') then DO;
  
  if B_CODE in ('11','12','13') then P='3';
  
  if B_CODE in ('14','15','16') then P='4';
  
  end;
  
  run;
  </code></pre>