<?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 Variable Format when Exporting to Excel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370073#M88391</link>
    <description>&lt;P&gt;Thanks for the help so far you all. As of now the code is still producing the incorrect output. There is no error according to the log either.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have updated the code to reflect the information given thus far: changed the numeric format to character formats in the data step and put single quotes around the numbers in the proc format step, but it does not apper to have actually changed anything. There are no leading zeros in the data from what I can tell. It might be worth mentioning that the values that are listed in the two columns (Greek, No Greek Affiliation) &amp;amp; (FR, SO, JR, etc.) are not directly from the tables, but are custom values based on critera that I have defined. I don't know if that should make a difference or not, but I can post the beginning of the code if necessary.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jun 2017 18:12:31 GMT</pubDate>
    <dc:creator>jpagitt</dc:creator>
    <dc:date>2017-06-23T18:12:31Z</dc:date>
    <item>
      <title>How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/369978#M88367</link>
      <description>&lt;P&gt;Good morning, all:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having trouble getting my code to retain its format when exporting to excel. I am using ODS EXCEL instead of something like PROC EXPORT so that I can retain the percentages in my data, but I have two fields that I used a format and then a subsequent data step to get into the desired order and when I export to Excel it gives me the numeric values instead of the alpha. Below is the last portion of my code where this is happening.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format;&lt;BR /&gt;value $GreekFlag&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;1='Greek'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;2='No Greek Affiliation';&lt;BR /&gt;value $ClassLevel&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;1='FR'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;2='SO'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;3='JR'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;4='SR'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;5='UGRD2'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;6='GR';&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data enrollment_formatted;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set enrollment_aggregated;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if greek_nongreek='Greek' then greek_nongreek='1';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if greek_nongreek='No Greek Affiliation' then greek_nongreek='2';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if class_level='FR' then class_level='1';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if class_level='SO' then class_level='2';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if class_level='JR' then class_level='3';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if class_level='SR' then class_level='4';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if class_level='UGRD2' then class_level='5';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if class_level='GR' then class_level='6';&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sort data=enrollment_formatted;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;by greek_nongreek class_level;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data enrollment_final;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set enrollment_formatted;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;format greek_nongreek $greekflag.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;format class_level $classlevel.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods excel file="\\filedestination.xlsx";&lt;BR /&gt;proc report data=enrollment_final;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;columns _all_;&lt;BR /&gt;run;&lt;BR /&gt;ods excel close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current output of the first two columns in excel:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Greek_NonGreek&lt;/TD&gt;&lt;TD&gt;Class_Level&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired output in the first two columns (and what is shown as my dataset in SAS):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Greek_NonGreek&lt;/TD&gt;&lt;TD&gt;Class_Level&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Greek&lt;/TD&gt;&lt;TD&gt;FR&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Greek&lt;/TD&gt;&lt;TD&gt;SO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Greek&lt;/TD&gt;&lt;TD&gt;JR&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Greek&lt;/TD&gt;&lt;TD&gt;SR&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Greek&lt;/TD&gt;&lt;TD&gt;GR&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;No Greek Afilliation&lt;/TD&gt;&lt;TD&gt;FR&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;No Greek Afilliation&lt;/TD&gt;&lt;TD&gt;SO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;No Greek Afilliation&lt;/TD&gt;&lt;TD&gt;JR&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;No Greek Afilliation&lt;/TD&gt;&lt;TD&gt;SR&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;No Greek Afilliation&lt;/TD&gt;&lt;TD&gt;UGRD2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;No Greek Afilliation&lt;/TD&gt;&lt;TD&gt;GR&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have seen some similar solutions, but nothing really touching on this. If you know of a paper/post that addresses this issue, a link to it would be much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 16:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/369978#M88367</guid>
      <dc:creator>jpagitt</dc:creator>
      <dc:date>2017-06-23T16:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370030#M88382</link>
      <description>&lt;P&gt;What version of SAS do you have? I would have expected that to be the default behaviour.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 17:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370030#M88382</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-23T17:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370032#M88383</link>
      <description>&lt;P&gt;Sorry - I meant to include that in the post. SAS 9.4&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 17:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370032#M88383</guid>
      <dc:creator>jpagitt</dc:creator>
      <dc:date>2017-06-23T17:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370035#M88384</link>
      <description>&lt;P&gt;Your code has other errors.&lt;/P&gt;
&lt;P&gt;I tried this with a proc print and it worked ok.&lt;/P&gt;
&lt;P&gt;I suspect your formats are incorrect - they're defined as character for one, when you've actually defined numeric data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So...I would check the rest of your code for other errors and try proc print, or writing out the full proc report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue you're having is likely identified in your log via a warning or error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value GreekFlag
    1='Greek'
    2='No Greek Affiliation';
value ClassLevel
    1='FR'
    2='SO'
    3='JR'
    4='SR'
    5='UGRD2'
    6='GR';
run;

data random;
do i=1 to 2;
do j=1 to 6;
output;
end;
end;


    format i greekflag.;
    format j classlevel.;

run;


ods excel file="c:\_localdata\temp\sample.xlsx";
proc print data=random;
run;
ods excel close;
 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="245"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="35"&gt;Obs&lt;/TD&gt;
&lt;TD width="147"&gt;i&lt;/TD&gt;
&lt;TD width="63"&gt;j&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Greek&lt;/TD&gt;
&lt;TD&gt;FR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;Greek&lt;/TD&gt;
&lt;TD&gt;SO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;Greek&lt;/TD&gt;
&lt;TD&gt;JR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;Greek&lt;/TD&gt;
&lt;TD&gt;SR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;Greek&lt;/TD&gt;
&lt;TD&gt;UGRD2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;Greek&lt;/TD&gt;
&lt;TD&gt;GR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;No Greek Affiliation&lt;/TD&gt;
&lt;TD&gt;FR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;No Greek Affiliation&lt;/TD&gt;
&lt;TD&gt;SO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;9&lt;/TD&gt;
&lt;TD&gt;No Greek Affiliation&lt;/TD&gt;
&lt;TD&gt;JR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;No Greek Affiliation&lt;/TD&gt;
&lt;TD&gt;SR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;TD&gt;No Greek Affiliation&lt;/TD&gt;
&lt;TD&gt;UGRD2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12&lt;/TD&gt;
&lt;TD&gt;No Greek Affiliation&lt;/TD&gt;
&lt;TD&gt;GR&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 17:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370035#M88384</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-23T17:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370058#M88389</link>
      <description>&lt;P&gt;I was unable to reproduce the error, so it must depend on an&amp;nbsp;environmental condition. In my opinion, the formats should work as coded, but I also tried them in this form, with the same results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;
value $GreekFlag
    '1'='Greek'
    '2'='No Greek Affiliation';
value $ClassLevel
    '1'='FR'
    '2'='SO'
    '3'='JR'
    '4'='SR'
    '5'='UGRD2'
    '6'='GR';
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a case like this, I would check for leading spaces in the character codes. Leading spaces won't always be displayed, but they can&amp;nbsp;interfere with the working of a character value format. However, I don't see anything in the logic that could have created leading spaces.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 18:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370058#M88389</guid>
      <dc:creator>RickAster</dc:creator>
      <dc:date>2017-06-23T18:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370073#M88391</link>
      <description>&lt;P&gt;Thanks for the help so far you all. As of now the code is still producing the incorrect output. There is no error according to the log either.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have updated the code to reflect the information given thus far: changed the numeric format to character formats in the data step and put single quotes around the numbers in the proc format step, but it does not apper to have actually changed anything. There are no leading zeros in the data from what I can tell. It might be worth mentioning that the values that are listed in the two columns (Greek, No Greek Affiliation) &amp;amp; (FR, SO, JR, etc.) are not directly from the tables, but are custom values based on critera that I have defined. I don't know if that should make a difference or not, but I can post the beginning of the code if necessary.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 18:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370073#M88391</guid>
      <dc:creator>jpagitt</dc:creator>
      <dc:date>2017-06-23T18:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370089#M88392</link>
      <description>&lt;P&gt;1. Post a snapshot of what your variables look like before proc report.&lt;/P&gt;
&lt;P&gt;2. What happens when you use proc print, instead of proc report?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 18:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370089#M88392</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-23T18:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370110#M88396</link>
      <description>&lt;P&gt;1. I feel like the code that I am using to produce the two fields might be more beneficial than a view at the tables. Here is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table Enrollment_base as&lt;BR /&gt;select distinct a.report_term, a.emplid, a.classification, a.acad_prog,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; case when a.emplid=b.emplid then "Greek" else "No Greek Affiliation" end as greek_flag,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; case when a.emplid=c.emplid then 1 else 0 end as returning_flag,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; case when a.emplid=d.emplid then 1 else 0 end as graduated_flag,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; case when a.classification='1' and a.acad_prog in ('UGRD','UGNDS') then 'FR'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; when a.classification='2' and a.acad_prog in ('UGRD','UGNDS') then 'SO'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; when a.classification='3' and a.acad_prog in ('UGRD','UGNDS') then 'JR'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; when a.classification='4' and a.acad_prog in ('UGRD','UGNDS') then 'SR'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; when a.acad_prog='UGRD2' then 'UGRD2'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; when a.classification in ('5', '6', '7', '8') then 'GR' end as Class_Level&lt;BR /&gt;from sqlserv.cbm001_augmented a&lt;BR /&gt;left join greek_population b&lt;BR /&gt;on a.emplid=b.emplid&lt;BR /&gt;left join returned c&lt;BR /&gt;on a.emplid=c.emplid&lt;BR /&gt;left join graduated d&lt;BR /&gt;on a.emplid=d.emplid&lt;BR /&gt;where a.report_term="&amp;amp;enrollterm";&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I am pretty new to SAS and coding in general, so I may not really understand your question, but I am not using proc print or proc report - at least I am not using those specific statements. My code is entirely made up of proc sql and data statements.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 19:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370110#M88396</guid>
      <dc:creator>jpagitt</dc:creator>
      <dc:date>2017-06-23T19:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370111#M88397</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/118326"&gt;@jpagitt&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;1. I feel like the code that I am using to produce the two fields might be more beneficial than a view at the tables. Here is the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, please post a proc contents of the dataset you're trying to export. We don't need to debug your entire code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=enrollment_final;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/118326"&gt;@jpagitt&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. I am pretty new to SAS and coding in general, so I may not really understand your question, but I am not using proc print or proc report - at least I am not using those specific statements. My code is entirely made up of proc sql and data statements.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please review the code you originally posted. There is a PROC REPORT in between the ODS EXCEL statements. I'm saying switch that to a PROC PRINT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=enrollment_final noobs label;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 19:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370111#M88397</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-23T19:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370132#M88399</link>
      <description>&lt;P&gt;Thanks for clearing that up for me. Below is a screenshot of the variables and attributes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9811i376D992D51C09FA7/image-size/original?v=1.0&amp;amp;px=-1" alt="Greek_Variables.JPG" title="Greek_Variables.JPG" border="0" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using PROC PRINT is as expected - it looks just like the SAS dataset when I look at it in the explorer.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13979i029CB79DBC99832F/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Greek_Variables.JPG" title="Greek_Variables.JPG" /&gt;</description>
      <pubDate>Fri, 23 Jun 2017 19:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370132#M88399</guid>
      <dc:creator>jpagitt</dc:creator>
      <dc:date>2017-06-23T19:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370142#M88401</link>
      <description>&lt;P&gt;Are your formats applied correctly in the dataset explorer or in the PROC PRINT output?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 19:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370142#M88401</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-23T19:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370144#M88402</link>
      <description>&lt;P&gt;Yes they are. It is only when I use ODS EXCEL to output to excel that I lose the format and the data uses the numeric values instead of the alpha values.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 19:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370144#M88402</guid>
      <dc:creator>jpagitt</dc:creator>
      <dc:date>2017-06-23T19:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370154#M88406</link>
      <description>&lt;P&gt;I ran your code exactly as written using the "Desired Output" table as input to create the "enrollment_aggregated" dataset (after correctling the spelling of the word "Affiliation") and the program produced the desired output in Excel(R).&amp;nbsp; &amp;nbsp; My spreadsheet contained the formatted values of the variables.&amp;nbsp; Thus, there must be some other problem(s) in your code Reeza suggested.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 20:24:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370154#M88406</guid>
      <dc:creator>DetBrik</dc:creator>
      <dc:date>2017-06-23T20:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370155#M88407</link>
      <description>&lt;P&gt;Do you mind posting the sample code that you used? Maybe there is something that you did slightly differently that I can glean from it. The log gives me no errors whatsoever, so finding it has proven quite difficult.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 20:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370155#M88407</guid>
      <dc:creator>jpagitt</dc:creator>
      <dc:date>2017-06-23T20:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370156#M88408</link>
      <description>&lt;P&gt;What happens when you run the example I originally posted?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What exact versio of SAS are you using? Ie SAS 9.4 TS1M4?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 20:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370156#M88408</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-23T20:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370158#M88410</link>
      <description>&lt;P&gt;When I run the example it does output with correct formats in excel, so that is good to know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Exact version is SAS 9.4 TS1M1&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 20:36:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370158#M88410</guid>
      <dc:creator>jpagitt</dc:creator>
      <dc:date>2017-06-23T20:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370159#M88411</link>
      <description>&lt;P&gt;ODS Excel is not production ready until SAS 9.4 TS1M3. Before that it was still in testing and there are bugs...&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 20:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370159#M88411</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-23T20:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370160#M88412</link>
      <description>&lt;P&gt;Here is the code I ran that produced the desired results.&amp;nbsp; I am using SAS 9.4 (TS1M3).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $GreekFlag
    1='Greek'
    2='No Greek Affiliation';
value $ClassLevel
    1='FR'
    2='SO'
    3='JR'
    4='SR'
    5='UGRD2'
    6='GR';
run;

data enrollment_aggregated;
input Greek_NonGreek $20. Class_Level $5.;
datalines;
Greek               FR 
Greek               SO 
Greek               JR 
Greek               SR 
Greek               GR 
No Greek AffiliationFR 
No Greek AffiliationSO 	
No Greek AffiliationJR 
No Greek AffiliationSR 
No Greek AffiliationUGRD2 
No Greek AffiliationGR 
;;;;
run;

data enrollment_formatted;
    set enrollment_aggregated;
    if greek_nongreek='Greek' then greek_nongreek='1';
        else if greek_nongreek='No Greek Affiliation' then greek_nongreek='2';
    if class_level='FR' then class_level='1';
        else if class_level='SO' then class_level='2';
        else if class_level='JR' then class_level='3';
        else if class_level='SR' then class_level='4';
        else if class_level='UGRD2' then class_level='5';
        else if class_level='GR' then class_level='6';
run;

proc sort data=enrollment_formatted;
    by greek_nongreek class_level;
run;

data enrollment_final;
    set enrollment_formatted;
    format greek_nongreek $greekflag.;
    format class_level $classlevel.;
run;

ods excel file="C:\_LocalPath\My SAS Files\9.4\Greek.xlsx";
proc report data=enrollment_final;
    columns _all_;
run;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;HTH.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 20:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370160#M88412</guid>
      <dc:creator>DetBrik</dc:creator>
      <dc:date>2017-06-23T20:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370164#M88414</link>
      <description>&lt;P&gt;Well, hopefully that explains it! I have a means of updating. I am going to reinstall with the correct version and then I will see if it works and post back here.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 20:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/370164#M88414</guid>
      <dc:creator>jpagitt</dc:creator>
      <dc:date>2017-06-23T20:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to Retain Variable Format when Exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/371037#M88629</link>
      <description>&lt;P&gt;I wanted to add that I updated SAS to 9.4 TS1M3 and my code works as expected. Turns out that is all I needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the help!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 19:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Retain-Variable-Format-when-Exporting-to-Excel/m-p/371037#M88629</guid>
      <dc:creator>jpagitt</dc:creator>
      <dc:date>2017-06-27T19:29:40Z</dc:date>
    </item>
  </channel>
</rss>

