<?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 How to combine two sas date environment variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-two-sas-date-environment-variables/m-p/890320#M351795</link>
    <description>&lt;P&gt;I want to combine outputs of sysdate and systime&lt;/P&gt;
&lt;P&gt;and get them in below format. I want the output to be stored in macro variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DDMMYYYY_HH:MM:SS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried doing like this but it is not working&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let dt=%sysfunc(put(&amp;amp;sysdate9,ddmmyy8.))||"_"||%sysfunc(put(&amp;amp;systime,tod8.));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Aug 2023 02:35:03 GMT</pubDate>
    <dc:creator>Sathya3</dc:creator>
    <dc:date>2023-08-22T02:35:03Z</dc:date>
    <item>
      <title>How to combine two sas date environment variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-two-sas-date-environment-variables/m-p/890320#M351795</link>
      <description>&lt;P&gt;I want to combine outputs of sysdate and systime&lt;/P&gt;
&lt;P&gt;and get them in below format. I want the output to be stored in macro variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DDMMYYYY_HH:MM:SS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried doing like this but it is not working&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let dt=%sysfunc(put(&amp;amp;sysdate9,ddmmyy8.))||"_"||%sysfunc(put(&amp;amp;systime,tod8.));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2023 02:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-two-sas-date-environment-variables/m-p/890320#M351795</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-08-22T02:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two sas date environment variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-two-sas-date-environment-variables/m-p/890323#M351797</link>
      <description>&lt;P&gt;You don't need to do much to combine macro variable values.&amp;nbsp; Just put the reference where you want the value to appear.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dt=&amp;amp;sysdate9._&amp;amp;systime.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;1    %put dt=&amp;amp;sysdate9._&amp;amp;systime.;
dt=21AUG2023_22:20
&lt;/PRE&gt;
&lt;P&gt;The reason your code failed is you tried to run code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dt=%sysfunc(put(&amp;amp;sysdate9,ddmmyy8.))||"_"||%sysfunc(put(&amp;amp;systime,tod8.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;First issue is that %SYSFUNC() cannot call the PUT() function (or the INPUT() function).&amp;nbsp; You can only use the type specific functions of PUTN() or PUTC() and INPUTN() or INPUTC().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second issue is that the PUTN() function needs a NUMERIC VALUE.&amp;nbsp; But you gave it the STRING value 21AUG2023 instead.&amp;nbsp; If you want to have SAS treat that string as a date you need to add quotes and the letter D to convert it into a date literal instead of just a string in the style generated by the DATE format.&amp;nbsp; Similarly for the time value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third issue is I don't think you really want to put double quote characters and pipe characters into the value of your new macro variable.&amp;nbsp; Instead I suspect you just wanted the underscore character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And finally I doubt you want to use only TWO digits for the YEAR value. So either use 10 for the width of the date format. Or use a format that does not use a delimiter so that 8 characters is enough to include the century number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And and it is best to avoid MDY or DMY ordering for date value. Whichever one you pick will cause confusion for half of your audience.&amp;nbsp; Was that July eight or the seventh of August?&lt;/P&gt;
&lt;PRE&gt;6    %put dt=%sysfunc(putn("&amp;amp;sysdate9"d,yymmddn8.))_%sysfunc(putn("&amp;amp;systime"t,tod8.));
dt=20230821_22:20:00
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2023 03:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-two-sas-date-environment-variables/m-p/890323#M351797</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-22T03:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine two sas date environment variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-two-sas-date-environment-variables/m-p/890324#M351798</link>
      <description>&lt;P&gt;I think you are looking for&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dt=%sysfunc(date(),ddmmyyn8.)_%sysfunc(time(),tod8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can test it with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;=dt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output will be&lt;/P&gt;
&lt;PRE&gt;DT=22082023_11:18:21&lt;/PRE&gt;
&lt;P&gt;There are several points you may want to know:&lt;/P&gt;
&lt;P&gt;1. put() function is not supported to be used in %sysfunc(), the replacement is putn() and putc() function;&lt;/P&gt;
&lt;P&gt;2. the macro function %sysfunc() has the second arguement, which allows us to write a format name here then %sysfunc() would return formatted value as we specified;&lt;/P&gt;
&lt;P&gt;3. the syntax is kind of different between macro language and data step language, connecting character can be very simple in macro language;&lt;/P&gt;
&lt;P&gt;4. ddmmyy8. will format date with slash, like 22/08/23, ddmmyyn8. will format date without slash, like 22082023;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2023 03:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-two-sas-date-environment-variables/m-p/890324#M351798</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-08-22T03:30:17Z</dc:date>
    </item>
  </channel>
</rss>

