<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Export String Data To CSV file with Corrected Format in Microsoft Integration with SAS</title>
    <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Export-String-Data-To-CSV-file-with-Corrected-Format/m-p/63194#M862</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
When exporting some data with string format (like 00021, 00005,...) to Excel or CSV via PROC EXPORT, the output file always converts the described data into numeric format (like 21, 5,...) automatically.&lt;BR /&gt;
&lt;BR /&gt;
Could you please let me know whether there are some methods to export the described data to Excel or CSV file with corrected format??&lt;BR /&gt;
&lt;BR /&gt;
Appreciate your advice!</description>
    <pubDate>Thu, 12 Aug 2010 16:09:22 GMT</pubDate>
    <dc:creator>BNG</dc:creator>
    <dc:date>2010-08-12T16:09:22Z</dc:date>
    <item>
      <title>Export String Data To CSV file with Corrected Format</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Export-String-Data-To-CSV-file-with-Corrected-Format/m-p/63194#M862</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
When exporting some data with string format (like 00021, 00005,...) to Excel or CSV via PROC EXPORT, the output file always converts the described data into numeric format (like 21, 5,...) automatically.&lt;BR /&gt;
&lt;BR /&gt;
Could you please let me know whether there are some methods to export the described data to Excel or CSV file with corrected format??&lt;BR /&gt;
&lt;BR /&gt;
Appreciate your advice!</description>
      <pubDate>Thu, 12 Aug 2010 16:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Export-String-Data-To-CSV-file-with-Corrected-Format/m-p/63194#M862</guid>
      <dc:creator>BNG</dc:creator>
      <dc:date>2010-08-12T16:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Export String Data To CSV file with Corrected Format</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Export-String-Data-To-CSV-file-with-Corrected-Format/m-p/63195#M863</link>
      <description>Hi:&lt;BR /&gt;
  When Excel sees a number with leading zeroes coming in from an exported data set or a CSV or HTML file (when that file is opened using Excel), Excel says -- "oh, I must use the general format for that number" and so Excel 'loses' the leading zeroes -- this causes issues with numbers like product ID or ID numbers or zip codes -- all of which could legitimately need to show leading zeroes.&lt;BR /&gt;
 &lt;BR /&gt;
  With CSV, you have no choice when you use ODS or PROC EXPORT to control the format that Excel will use when it opens the file -- mostly because the SAS format for leading zeroes is ignored by Excel. So, the solution is to create either an HTML file or an XML file that Excel can render into spreadsheet form. With either HTML-based output or XML-based output (Spreadsheet Markup Language file), you can send a &lt;B&gt;Microsoft&lt;/B&gt; format from SAS and ODS to Excel.&lt;BR /&gt;
 &lt;BR /&gt;
  Consider the following data:&lt;BR /&gt;
[pre]&lt;BR /&gt;
**1) make some data -- SAMPLE is a character variable;&lt;BR /&gt;
data tkt_alt;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input sample $ dest $ type $  amt;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
00010 CHICAGO   TEL    100  &lt;BR /&gt;
00222 CHICAGO   TEL    200  &lt;BR /&gt;
00330 GENEVA    WEB    300  &lt;BR /&gt;
00040 GENEVA    WEB    400  &lt;BR /&gt;
00550 LONDON    TEL    500  &lt;BR /&gt;
00066 LONDON    TEL    600  &lt;BR /&gt;
00777 LONDON    WEB    700  &lt;BR /&gt;
00088 PARIS     TEL    800  &lt;BR /&gt;
00990 PARIS     WEB    900  &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                     &lt;BR /&gt;
 &lt;BR /&gt;
If you want to send the TKT_ALT data to Excel, it would normally not show the leading zeroes for the SAMPLE variable. However, if I make either an HTML file that Excel can open or an XML file that Excel can open, I can send a Microsoft format from SAS to Excel.&lt;BR /&gt;
 [pre]&lt;BR /&gt;
ods listing close;&lt;BR /&gt;
                                   &lt;BR /&gt;
** 2) make an HTML file and use HTMLSTYLE to send a MICROSOFT format to the HTML;&lt;BR /&gt;
ods msoffice2k file="c:\temp\msofmt.xls" style=sasweb;&lt;BR /&gt;
  proc print data=tkt_alt noobs label;&lt;BR /&gt;
    title 'Using HTMLSTYLE to send Microsoft MSO Format';&lt;BR /&gt;
      var sample /  &lt;BR /&gt;
          style(column)={HTMLSTYLE="mso-number-format:00000"};&lt;BR /&gt;
      var dest type amt;&lt;BR /&gt;
  run; &lt;BR /&gt;
ods msoffice2k close;&lt;BR /&gt;
                                  &lt;BR /&gt;
** 3) make an XML file and use TAGATTR to send a MICROSOFT format to the XML;&lt;BR /&gt;
ods tagsets.excelxp file="c:\temp\xpfmt.xls" style=sasweb;&lt;BR /&gt;
  proc print data=tkt_alt noobs label;&lt;BR /&gt;
    title 'Using TAGATTR to send Microsoft Format';&lt;BR /&gt;
      var sample /  &lt;BR /&gt;
          style(column)={TAGATTR="Format:00000"};&lt;BR /&gt;
      var dest type amt;&lt;BR /&gt;
  run; &lt;BR /&gt;
ods tagsets.excelxp close;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
Do note that when I give the files a ".XLS" extension, I am merely "fooling" the Windows Registry into launching Excel when the file is double-clicked. You can verify what's inside each file by opening the file with Notepad to see either the HTML tags or the XML tags in the files that are created by ODS. &lt;BR /&gt;
 &lt;BR /&gt;
If you are using SAS Enterprise Guide, you will NOT be able to open the TAGSETS.EXCELXP results with Excel from within SAS Enterprise Guide -- you will have to open Excel and do a File --&amp;gt; Open from within Excel in order to open the file. When you get prompted that the contents of the file do not match the file extension -- do not worry, that is just Microsoft making sure that nothing in the file will corrupt your computer. It's OK to click YES to open the file.&lt;BR /&gt;
 &lt;BR /&gt;
Also note that you cannot cut and paste code directly from the forum posting mechanism into SAS or into an EG code node. You will have to cut and paste the code one time from the forum into Word in order to preserve the line breaks and then cut and paste from Word into SAS in order to have the line breaks recognized in the SAS code window. Then you can submit the code and review the results.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 13 Aug 2010 03:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Export-String-Data-To-CSV-file-with-Corrected-Format/m-p/63195#M863</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-13T03:13:38Z</dc:date>
    </item>
  </channel>
</rss>

