title: Splitting a Delimited String Variable in SAS into Individual Variables
body: <p>I'm hoping someone can help me out with this issue. I am trying to take a string variable which contains a series of delimited pick list responses. There can be no response, one response (e.g., 1234), or several responses (e.g., 1234;9876) in a single variable. Different options are always delimited by a semicolon (;). I'd like to split this single variable into multiple variables based on the delimiter.</p>
  
  <p>For example, reasons=1234;9876 -> reason1=1234, reason2=9876</p>
  
  <p>Traditionally I have done this the manual way using the scan function. The problem is I have up to (in this case) 10 pick list items concatenated in a single string.</p>
  
  <pre><code>data want;
  set got;
     length reason1-reason10 $10;
       if reasons ne ' ' then reason1=scan(reasons, 1, ';');
       if reasons ne ' ' then reason2=scan(reasons, 2, ';');
       if reasons ne ' ' then reason3=scan(reasons, 3, ';');
   ...
   run;
  </code></pre>
  
  <p>and so on...</p>
  
  <p>I feel like an array would greatly simplify this process. However, I am now just learning how to use arrays. Any advice on how to split this string variable with more efficient code would be greatly appreciated. Thanks!</p>