<?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 Changing the date from numeric to date format before exporting to Excel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-the-date-from-numeric-to-date-format-before-exporting/m-p/787108#M251423</link>
    <description>&lt;P&gt;I have an end table, and I would like to export these results to Excel, however, after aggregation I changed the data from date format to numeric and when exporting to Excel it converts date to numbers. It is possible to change this value to a date before export&lt;/P&gt;
&lt;PRE&gt;DATA2DATASTEP DSN &amp;#6;FINAL_WYGASLE&amp;#8;
DATA2DATASTEP FILE 5
DATA2DATASTEP FMT &amp;#6;YES&amp;#8;
DATA2DATASTEP FMTLIST policy_vintage VINTF.
DATA2DATASTEP INPUTLIST policy_vintage:VINTF. TODAY:32. PREV_MONTH:32. PREV_WEEK:32. DIFF_WEEK:32. DIFF_MONTH:32.
DATA2DATASTEP LBL &amp;#6;YES&amp;#8;
DATA2DATASTEP LIB &amp;#6;WORK&amp;#8;
DATA2DATASTEP MEMLABEL 
DATA2DATASTEP MSGTYPE NOTE
DATA2DATASTEP OBS MAX
DATA2DATASTEP OUTLIB WORK
DATA2DATASTEP VARLIST policy_vintage TODAY PREV_MONTH PREV_WEEK DIFF_WEEK DIFF_MONTH&lt;/PRE&gt;
&lt;P&gt;Below is my code :&lt;/P&gt;
&lt;PRE&gt;proc sql;
    create table diff_policy_exp as
		select
		 wyg.policy_vintage as policy_vintage
			 ,wyg.WYGASLE as TODAY
			 ,prior.WYGASLE as PREV_WEEK
			 ,wyg.WYGASLE - prior.WYGASLE as DIFF_WEEK
        from policy_vintage_weekly1 wyg
		        LEFT JOIN
             (select *
              from _work.policy_weekly
              where run_date &amp;lt; today() 
              having run_date = max(run_date)
             ) prior
        ON wyg.policy_vintage = prior.policy_vintage
;
quit;
proc sql;
create table diff_policy_exp as
select
t1.policy_vintage
,t1.TODAY
,t1.PREV_WEEK
,t1.DIFF_WEEK
,t2.PREV_MONTH
,t1.today - t2.prev_month as DIFF_MONTH
from diff_policy_exp t1
left join ( select policy_vintage, PREV_MONTH from policy_vintage_weekly_p1) t2
on t1.policy_vintage = t2.policy_vintage
;
quit;
/*tworzymy zmienną DATE_OLD do grupowania*/
%let date_old=%sysfunc(intnx(year,%sysfunc(Today()),-1,s));
proc format;
value vintf
  low-&amp;amp;date_old = 'OLD'
  other=[yymmd7.]
;
run;
/*agregujemy wyniki do daty vintf jako old*/
proc summary data=diff_policy_exp nway;
    class policy_vintage;
    format policy_vintage vintf.;
    var TODAY PREV_WEEK PREV_MONTH DIFF_WEEK DIFF_MONTH;
    output out=diff_policy_exp sum=;
proc sql;
create table final_wygasle as
select
policy_vintage
,TODAY 
,PREV_MONTH
,PREV_WEEK 
,DIFF_WEEK
,DIFF_MONTH
from diff_policy_exp
;
quit;&lt;/PRE&gt;
&lt;P&gt;Here what i have in SAS :&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Gieorgie_0-1640182767679.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66930i01BF836CA050CB48/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Gieorgie_0-1640182767679.png" alt="Gieorgie_0-1640182767679.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here what i got in Excel :&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Gieorgie_1-1640182794828.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66931iB1DB12840604E3C2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Gieorgie_1-1640182794828.png" alt="Gieorgie_1-1640182794828.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Dec 2021 14:20:07 GMT</pubDate>
    <dc:creator>Gieorgie</dc:creator>
    <dc:date>2021-12-22T14:20:07Z</dc:date>
    <item>
      <title>Changing the date from numeric to date format before exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-the-date-from-numeric-to-date-format-before-exporting/m-p/787108#M251423</link>
      <description>&lt;P&gt;I have an end table, and I would like to export these results to Excel, however, after aggregation I changed the data from date format to numeric and when exporting to Excel it converts date to numbers. It is possible to change this value to a date before export&lt;/P&gt;
&lt;PRE&gt;DATA2DATASTEP DSN &amp;#6;FINAL_WYGASLE&amp;#8;
DATA2DATASTEP FILE 5
DATA2DATASTEP FMT &amp;#6;YES&amp;#8;
DATA2DATASTEP FMTLIST policy_vintage VINTF.
DATA2DATASTEP INPUTLIST policy_vintage:VINTF. TODAY:32. PREV_MONTH:32. PREV_WEEK:32. DIFF_WEEK:32. DIFF_MONTH:32.
DATA2DATASTEP LBL &amp;#6;YES&amp;#8;
DATA2DATASTEP LIB &amp;#6;WORK&amp;#8;
DATA2DATASTEP MEMLABEL 
DATA2DATASTEP MSGTYPE NOTE
DATA2DATASTEP OBS MAX
DATA2DATASTEP OUTLIB WORK
DATA2DATASTEP VARLIST policy_vintage TODAY PREV_MONTH PREV_WEEK DIFF_WEEK DIFF_MONTH&lt;/PRE&gt;
&lt;P&gt;Below is my code :&lt;/P&gt;
&lt;PRE&gt;proc sql;
    create table diff_policy_exp as
		select
		 wyg.policy_vintage as policy_vintage
			 ,wyg.WYGASLE as TODAY
			 ,prior.WYGASLE as PREV_WEEK
			 ,wyg.WYGASLE - prior.WYGASLE as DIFF_WEEK
        from policy_vintage_weekly1 wyg
		        LEFT JOIN
             (select *
              from _work.policy_weekly
              where run_date &amp;lt; today() 
              having run_date = max(run_date)
             ) prior
        ON wyg.policy_vintage = prior.policy_vintage
;
quit;
proc sql;
create table diff_policy_exp as
select
t1.policy_vintage
,t1.TODAY
,t1.PREV_WEEK
,t1.DIFF_WEEK
,t2.PREV_MONTH
,t1.today - t2.prev_month as DIFF_MONTH
from diff_policy_exp t1
left join ( select policy_vintage, PREV_MONTH from policy_vintage_weekly_p1) t2
on t1.policy_vintage = t2.policy_vintage
;
quit;
/*tworzymy zmienną DATE_OLD do grupowania*/
%let date_old=%sysfunc(intnx(year,%sysfunc(Today()),-1,s));
proc format;
value vintf
  low-&amp;amp;date_old = 'OLD'
  other=[yymmd7.]
;
run;
/*agregujemy wyniki do daty vintf jako old*/
proc summary data=diff_policy_exp nway;
    class policy_vintage;
    format policy_vintage vintf.;
    var TODAY PREV_WEEK PREV_MONTH DIFF_WEEK DIFF_MONTH;
    output out=diff_policy_exp sum=;
proc sql;
create table final_wygasle as
select
policy_vintage
,TODAY 
,PREV_MONTH
,PREV_WEEK 
,DIFF_WEEK
,DIFF_MONTH
from diff_policy_exp
;
quit;&lt;/PRE&gt;
&lt;P&gt;Here what i have in SAS :&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Gieorgie_0-1640182767679.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66930i01BF836CA050CB48/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Gieorgie_0-1640182767679.png" alt="Gieorgie_0-1640182767679.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here what i got in Excel :&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Gieorgie_1-1640182794828.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66931iB1DB12840604E3C2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Gieorgie_1-1640182794828.png" alt="Gieorgie_1-1640182794828.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 14:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-the-date-from-numeric-to-date-format-before-exporting/m-p/787108#M251423</guid>
      <dc:creator>Gieorgie</dc:creator>
      <dc:date>2021-12-22T14:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the date from numeric to date format before exporting to Excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-the-date-from-numeric-to-date-format-before-exporting/m-p/787116#M251427</link>
      <description>&lt;P&gt;You won't be able to do this automatically, as your formatted value "OLD" can't be recognized by Excel as a date.&lt;/P&gt;
&lt;P&gt;Change your SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table final_wygasle as
select
put(policy_vintage,vintf.) as policy_vintage
,TODAY 
,PREV_MONTH
,PREV_WEEK 
,DIFF_WEEK
,DIFF_MONTH
from diff_policy_exp
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so that the data ends as character in Excel.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 15:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-the-date-from-numeric-to-date-format-before-exporting/m-p/787116#M251427</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-12-22T15:10:47Z</dc:date>
    </item>
  </channel>
</rss>

