title: SAS how to extract multiple words from a string
body: <p>I have a list of multiple-length degree programs that include the degree type (e.g., PhD) and I want to delete the degree type and keep just the program name. e.g.:  </p>
  
  <pre><code>Master of Science in Building Performance and Diagnostics
  Master of Science in Computational Design  
  Master of Science in Sustainable Design 
  Master of Urban Design 
  PhD in Architecture 
  </code></pre>
  
  <p>I am trying to use scan to split the string on "in " and extract all text that follows, but I don't understand the result I'm getting. When I use -1 (start from the right) as the starting point I get: </p>
  
  <pre><code>data want; 
      format new_prog old_prog $200.; 
      set have (rename = (program = old_prog)); 
      if count(old_prog, " in ") ge 1 then new_prog = scan(old_prog, -1, "in "); 
  run; 
  
  
  new_prog  old_prog
  tecture   Master of Science in Architecture 
  g         Master of Science in Sustainable Design 
  cs        Master of Science in Building Performance and Diagnostics 
  t         Master of Science in Architecture-Engineering and Construction Management 
  </code></pre>
  
  <p>I don't think this would work anyway since I want the entire string after "in " and not just the next word, but even if I use scan(old_prog, 2, "in") I expect this to give me the next word but it seems to be giving me random stuff, e.g.: </p>
  
  <pre><code>program  old_prog 
  Bu       PhD in Building Performance and Diagnostics 
  of       Master of Science in Architecture-Engineering and Construction Management 
  Computat PhD in Computational Design 
  of       Master of Science in Sustainable Design 
  </code></pre>