<?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: SAS date format conversion and assigning to macro variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format-conversion-and-assigning-to-macro-variables/m-p/949969#M371533</link>
    <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314145"&gt;@Emoji&lt;/a&gt;! The reason this is occurring is because formats are for visually displaying a value. The underlying value you have is still just a number - in this case, it's the number of days since Jan 1st 1960. One easy way to remember this: &lt;STRONG&gt;for&lt;/STRONG&gt;mats are&amp;nbsp;&lt;STRONG&gt;for&lt;/STRONG&gt; you to view.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make sure your macro variable takes on the date format you want, convert the SAS date to a string of the format you want with a PUT function. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    call symputx('_hist', put('05NOV2024'd, ddmmyyd10.));
run;

%put &amp;amp;=_HIST;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;_HIST=05-11-2024&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Bonus&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Now if you want to optimize your code, you can actually use SQL instead and do it all in one step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select max(opr_date) format=ddmmyyd10.
    into :_hist
    from input;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Okay, now you might be wondering why you don't need to use&amp;nbsp;PUT here. SQL SELECT INTO is an exception to the rule. It will send your formatted value to the macro variable automatically.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Nov 2024 20:25:02 GMT</pubDate>
    <dc:creator>Stu_SAS</dc:creator>
    <dc:date>2024-11-05T20:25:02Z</dc:date>
    <item>
      <title>SAS date format conversion and assigning to macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format-conversion-and-assigning-to-macro-variables/m-p/949967#M371532</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code and trying to assign the date to _hist macro and I need to make sure that that value assigned to _hist is going to be DD-MON-YYYY (like 05-Nov-2024). However, my code assign value of&amp;nbsp;23685 to the macro which is not what I want (date in the input table is in format/informat of DATETIME20.)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;DATA WORK.RECENT;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SET WORK.INPUT END = ISLAST;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DATE = DATEPART(DATE);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IF ISLAST THEN&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;OUTPUT;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;FORMAT OPR_DATE DATE11.;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;DATA _NULL_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;SET WORK.RECENT;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;CALL SYMPUT('_HIST',DATE);&lt;BR /&gt;RUN;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%PUT &amp;amp;=_HIST;&lt;/DIV&gt;</description>
      <pubDate>Tue, 05 Nov 2024 19:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format-conversion-and-assigning-to-macro-variables/m-p/949967#M371532</guid>
      <dc:creator>Emoji</dc:creator>
      <dc:date>2024-11-05T19:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format conversion and assigning to macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format-conversion-and-assigning-to-macro-variables/m-p/949969#M371533</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314145"&gt;@Emoji&lt;/a&gt;! The reason this is occurring is because formats are for visually displaying a value. The underlying value you have is still just a number - in this case, it's the number of days since Jan 1st 1960. One easy way to remember this: &lt;STRONG&gt;for&lt;/STRONG&gt;mats are&amp;nbsp;&lt;STRONG&gt;for&lt;/STRONG&gt; you to view.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make sure your macro variable takes on the date format you want, convert the SAS date to a string of the format you want with a PUT function. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    call symputx('_hist', put('05NOV2024'd, ddmmyyd10.));
run;

%put &amp;amp;=_HIST;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;_HIST=05-11-2024&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Bonus&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Now if you want to optimize your code, you can actually use SQL instead and do it all in one step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select max(opr_date) format=ddmmyyd10.
    into :_hist
    from input;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Okay, now you might be wondering why you don't need to use&amp;nbsp;PUT here. SQL SELECT INTO is an exception to the rule. It will send your formatted value to the macro variable automatically.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 20:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format-conversion-and-assigning-to-macro-variables/m-p/949969#M371533</guid>
      <dc:creator>Stu_SAS</dc:creator>
      <dc:date>2024-11-05T20:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format conversion and assigning to macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format-conversion-and-assigning-to-macro-variables/m-p/949973#M371535</link>
      <description>&lt;P&gt;Another tip.&amp;nbsp; Only using the ancient CALL SYMPUT() routine if it is important that the resulting macro variable contains leading and/or trailing spaces.&amp;nbsp; &amp;nbsp;Otherwise use the new (available since at least version 6 of SAS) CALL SYMPUTX() routine, which automatically remove the trailing and leading spaces.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 21:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format-conversion-and-assigning-to-macro-variables/m-p/949973#M371535</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-05T21:40:39Z</dc:date>
    </item>
  </channel>
</rss>

