<?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 Re: How to retain the Variable Format when PROC EXPORT TO EXCEL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357110#M64268</link>
    <description>&lt;P&gt;It is not possible with proc export to retain formats. &amp;nbsp;It is a plain data dump to Excel - and then you get all the "features" of Excel like dropping preceding zeros and such like. &amp;nbsp;If you are creating a report and it needs to have special formatting and such like then you need to write the code to do this. &amp;nbsp;Up to now I would use ods tagsets.excelxp and proc report, however &lt;A href="https://go.documentation.sas.com/?docsetId=odsug&amp;amp;docsetTarget=p09n5pw9ol0897n1qe04zeur27rv.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;the ods excel now creates native XLSX files&lt;/A&gt;, so best to go with that if you can. &amp;nbsp;This should also retain the formatted value, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $sex
    "M"="Male"
    "F"="Female";
run;

data want;
  set sashelp.class;
  format sex $sex.;
run;

/* Note for older versions of sas you could use
ods tagsets.excelxp file="c:\test.xml";
   To get the same result */

ods excel file="c:\test.xlsx";
proc report data=want;
  columns _all_;
run;
ods excel close;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want special formatting from Excel then add a row for each column that needs it and use define / style=...&lt;/P&gt;</description>
    <pubDate>Thu, 13 Sep 2018 17:58:34 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-09-13T17:58:34Z</dc:date>
    <item>
      <title>How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357108#M64267</link>
      <description>&lt;P&gt;Dear All,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am facing an frustrating problem: when I use PROC EXPORT to export data (with many variables have format ) to EXCEL, I found the format is lost, e.g. SEX only appear 1 or 2 &amp;nbsp;in EXCEL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have searched in our community, but no easy way. Like ODS EXCEL+PROC REPORT, since many variable have their formats, then it is not a fun thing to define each variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I know if there is an easy way?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;BR /&gt;Jack&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 09:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357108#M64267</guid>
      <dc:creator>Jack2012</dc:creator>
      <dc:date>2017-05-09T09:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357110#M64268</link>
      <description>&lt;P&gt;It is not possible with proc export to retain formats. &amp;nbsp;It is a plain data dump to Excel - and then you get all the "features" of Excel like dropping preceding zeros and such like. &amp;nbsp;If you are creating a report and it needs to have special formatting and such like then you need to write the code to do this. &amp;nbsp;Up to now I would use ods tagsets.excelxp and proc report, however &lt;A href="https://go.documentation.sas.com/?docsetId=odsug&amp;amp;docsetTarget=p09n5pw9ol0897n1qe04zeur27rv.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;the ods excel now creates native XLSX files&lt;/A&gt;, so best to go with that if you can. &amp;nbsp;This should also retain the formatted value, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $sex
    "M"="Male"
    "F"="Female";
run;

data want;
  set sashelp.class;
  format sex $sex.;
run;

/* Note for older versions of sas you could use
ods tagsets.excelxp file="c:\test.xml";
   To get the same result */

ods excel file="c:\test.xlsx";
proc report data=want;
  columns _all_;
run;
ods excel close;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want special formatting from Excel then add a row for each column that needs it and use define / style=...&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 17:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357110#M64268</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-13T17:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357279#M64281</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/7887"&gt;@Jack2012&lt;/a&gt;: There is an easy way. Download and run the free macro at:&amp;nbsp;&lt;A href="http://www.sascommunity.org/wiki/A_Poor/Rich_SAS_Users_Proc_Export" target="_blank"&gt;http://www.sascommunity.org/wiki/A_Poor/Rich_SAS_Users_Proc_Export&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, the following example will do exactly what I think you said you want to do:&lt;/P&gt;
&lt;PRE&gt;proc format;
  value $gender
  'M'='Male'
  other='Female'
  ;
  
  value age
  low-13='young'
  other='not as young'
  ;
run;

data class;
  set sashelp.class;
  format sex $gender.;
  format age age.;
run;

%exportxl(data=class,
                outfile=c:\art\class.xlsx,
                useformats=Y)
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 19:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357279#M64281</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-09T19:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357719#M64299</link>
      <description>&lt;P&gt;Thanks Art, the problem, after I read the code in the link, is the format of my data is not stored in the DICTIONARY library, actually there is no such library. I am lost which one to use as instead of DICTIONARY since I have no idea about the such library.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 01:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357719#M64299</guid>
      <dc:creator>Jack2012</dc:creator>
      <dc:date>2017-05-11T01:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357724#M64300</link>
      <description>&lt;P&gt;Highly appreciated for your proposal. I think the ODS EXCEL works for me at present.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 01:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357724#M64300</guid>
      <dc:creator>Jack2012</dc:creator>
      <dc:date>2017-05-11T01:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357727#M64301</link>
      <description>&lt;P&gt;The metadata for ALL SAS datasets is stored in the various dictionary files .. NO EXCEPTIONS! The files are automatically built and maintained by the software.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 01:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357727#M64301</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-11T01:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357740#M64302</link>
      <description>&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;You can run the code below to see some of the table metadata:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $gender 'M'='Male'
                other='Female';
  
  value age low-13='young'
            other='not as young';
run; quit;

data work.class;
set sashelp.class;
format sex $gender.;
format age age.;
run;

title 'SASHELP.VCOLUMN - PROC PRINT';

proc print data=sashelp.vcolumn noobs label;
  where (libname eq 'WORK' and memname eq 'CLASS');
  var name type length format;
run; quit;

title 'DICTIONARY.COLUMNS - PROC SQL';

proc sql;
  select name, type, length, format
  from dictionary.columns
  where (libname eq 'WORK' and memname eq 'CLASS');
quit;  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;Vince DelGobbo&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;SAS R&amp;amp;D&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 02:33:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/357740#M64302</guid>
      <dc:creator>Vince_SAS</dc:creator>
      <dc:date>2017-05-11T02:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/442470#M69300</link>
      <description>&lt;P&gt;&lt;img id="robotvery-happy" class="emoticon emoticon-robotvery-happy" src="https://communities.sas.com/i/smilies/16x16_robot-very-happy.png" alt="Robot Very Happy" title="Robot Very Happy" /&gt;&lt;/P&gt;&lt;P&gt;I had the same issue. I was able to get around it by&amp;nbsp;loading the variable with the custom format to another string variable...&lt;/P&gt;&lt;P&gt;data YOURDATA;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set YOURDATA;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;format SWAP $50.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;SWAP = PUT(FORMATTED_VALUE, $CUSTOM_FORMAT.);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;run;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 18:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/442470#M69300</guid>
      <dc:creator>mich1</dc:creator>
      <dc:date>2018-03-05T18:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/475425#M71159</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;, I get these errors while running the macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MACROGEN(EXPORTXL): put m;&lt;/P&gt;&lt;P&gt;MACROGEN(EXPORTXL): rc=filename('code2inc');&lt;/P&gt;&lt;P&gt;MACROGEN(EXPORTXL): stop;&lt;/P&gt;&lt;P&gt;MACROGEN(EXPORTXL): end;&lt;/P&gt;&lt;P&gt;MACROGEN(EXPORTXL): run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;ERROR: Undetermined I/O failure.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MACROGEN(EXPORTXL): call system('cscript "P:\work\_TD8972_JAMES_\Prc2\PasteIt.vbs"' );&lt;/P&gt;&lt;P&gt;MACROGEN(EXPORTXL): run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;ERROR: Shell escape is not valid in this SAS session.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;&lt;FONT color="#000000"&gt;Does my admin need to allow me to run the VBS via shell or something?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jul 2018 12:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/475425#M71159</guid>
      <dc:creator>PavelD</dc:creator>
      <dc:date>2018-07-04T12:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/475430#M71161</link>
      <description>&lt;P&gt;Yes! The macro was designed to run on base SAS using a Windows operating system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jul 2018 12:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/475430#M71161</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-07-04T12:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/789596#M81426</link>
      <description>&lt;P&gt;I download the code from&amp;nbsp;&lt;A href="https://github.com/art297/Papers/blob/master/Excelling_to_Another_Level_with_SAS/src/exportxl.sas" target="_blank"&gt;https://github.com/art297/Papers/blob/master/Excelling_to_Another_Level_with_SAS/src/exportxl.sas&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Getting an error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Undetermined I/O failure.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 21:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/789596#M81426</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2022-01-11T21:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/882747#M82809</link>
      <description>&lt;P&gt;Thanks would like to know if we import back the same file in SAS will it be same as dataset we exported into excel.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2023 07:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/882747#M82809</guid>
      <dc:creator>Nikhiljain22740</dc:creator>
      <dc:date>2023-06-28T07:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/882750#M82810</link>
      <description>&lt;P&gt;Hi, do bear in mind this topic was closed 6 years ago.&amp;nbsp; Its a good idea to open new questions as things will have changed in that time. &lt;/P&gt;
&lt;P&gt;In terms of will the data be the same when imported back, the answer is it will retain the data part, however anything SAS specific will not, so if you export:&lt;/P&gt;
&lt;P&gt;A&amp;nbsp;&amp;nbsp; B&amp;nbsp; C&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will get a dataset with columns named A,B,C, and one row of data 1,2,3, but you will not necessarily get the right length, format, informat.&amp;nbsp; And also depending on language settings/special characters etc. the data might be different too.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2023 08:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/882750#M82810</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2023-06-28T08:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the Variable Format when PROC EXPORT TO EXCEL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/951173#M83772</link>
      <description>&lt;P&gt;This doesn't work for a large dataset, you receive an out of memory error.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 01:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-retain-the-Variable-Format-when-PROC-EXPORT-TO-EXCEL/m-p/951173#M83772</guid>
      <dc:creator>dbf</dc:creator>
      <dc:date>2024-11-19T01:46:10Z</dc:date>
    </item>
  </channel>
</rss>

