title: Export R data.frame to SPSS
body: <p>There is a package <code>foreign</code> with a function <code>write.foreign()</code> that can write a SPS and CSV file. The SPS file than can read the CSV fiel into SPSS including labels. Fine so far, but there are some issues with that function:</p>
  
  <ol>
  <li>Newer SPSS versions may show an error that you have too few format definitions in <code>DATA LIST</code></li>
  <li>If there are "labels" for numeric variables stored via <code>attr()</code>, these are lost.</li>
  <li>Even if the SPSS vesion supports strings up to 32767, the function <code>write.foreign()</code> stops if there are more than 255 in any variable.</li>
  <li>Theres a star (*) if any character variables are used, but newer SPSS versions cannot handle that.</li>
  <li>The CSV file is comma-separated and does (can) not use quotes, therefore no commas are allowed in strings (character)</li>
  <li>Non-ASCII caracters (e.g. umlauts) will crash the import</li>
  <li>Should you have a character that contains any NA value, you'll see...</li>
  </ol>
  
  <p>... an error message like this:</p>
  
  <pre><code>Error in if (any(lengths &gt; 255L)) stop("Cannot handle character variables longer than 255") : 
      missing value where TRUE/FALSE needed
  </code></pre>
  
  <p>I spent a lot of time with that and then found a good posting (<a href="http://r.789695.n4.nabble.com/SPSS-export-in-R-package-foreign-td921491.html" rel="noreferrer">http://r.789695.n4.nabble.com/SPSS-export-in-R-package-foreign-td921491.html</a>) to start on and make it better. Here's my result, I'd like to share with you.</p>