<?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: unable to store datetime value in a macro variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149471#M39451</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay,let me clarify,&amp;nbsp; I put up some code at home , based on the student version on VMWARE and the available tables. (As mentioned)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The actual program I'm working on I cannot access from home, hence the example(s) from VMWARE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The actual idea is to store the timestamp from the beginning of the process (it takes about 3 minutes to run from begin to end) and then add the timestamp for reporting purposes to the resulting reporting table. (at the end)&lt;/P&gt;&lt;P&gt;The concept of applying a format is not easily adopted after working 20 year with each and every possible relational database, but I think that Cynthia really made it very clear.&amp;nbsp; Thanks for your feedback !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 13 Dec 2014 18:57:55 GMT</pubDate>
    <dc:creator>blom0344</dc:creator>
    <dc:date>2014-12-13T18:57:55Z</dc:date>
    <item>
      <title>unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149465#M39445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I'm trying to store the datetime() value into a macro variable for use within a little program:&amp;nbsp; (example with the baseball table of the VMware student edition )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table work.start_falnr as&lt;BR /&gt;select max(nhits) as max_hits,&lt;BR /&gt;round(datetime()) as process_start_integer,&lt;BR /&gt;put(datetime(),is8601dt.) as tstamp,&lt;BR /&gt;datetime() as process_start &lt;BR /&gt;from sashelp.baseball;&lt;BR /&gt;quit; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select max_hits,process_start_integer,process_start,tstamp into&lt;BR /&gt;:max_hits,:process1,:process2,:tstamp&lt;BR /&gt;from work.start_falnr;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table work.output as &lt;BR /&gt;select process_start_integer,&amp;amp;max_hits,&amp;amp;process1,&amp;amp;process2,&amp;amp;tstamp from work.start_falnr;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The actual exact value of&amp;nbsp; process_start_integer&amp;nbsp; is&amp;nbsp; 1734088402.,&amp;nbsp; but the values written to the output table&amp;nbsp; are&amp;nbsp; 1734100000 and 1734100000&amp;nbsp; resp. for process1 and process2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why can I not store the exact value this way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The tstamp value&amp;nbsp; (put(datetime(),is8601dt.) )&amp;nbsp; yields an error message in the last&amp;nbsp; proc sql&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Dec 2014 16:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149465#M39445</guid>
      <dc:creator>blom0344</dc:creator>
      <dc:date>2014-12-13T16:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149466#M39446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use:&lt;/P&gt;&lt;P&gt;%let datetime_var = "%sysfunc(datetime(),datetime19.)"dt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then use this anywhere as an macro variable @datetime_var&lt;/P&gt;&lt;P&gt;Hope this help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Dec 2014 17:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149466#M39446</guid>
      <dc:creator>Hercules</dc:creator>
      <dc:date>2014-12-13T17:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149467#M39447</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you are calling DATETIME() function three times you could possibly get three different times depending on when the function calls actually run.&lt;/P&gt;&lt;P&gt;If you just want one value then call the function only once.&amp;nbsp; Why not just call it using macro code instead of PROC SQL?&lt;/P&gt;&lt;P&gt;%let start_time = %sysfunc(datetime());&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Dec 2014 18:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149467#M39447</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-12-13T18:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149468#M39448</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;using @datetime_var&amp;nbsp; yields an error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code I'm using is not wrapped up within a macro, perhaps I need to wrap it up in there?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;put(datetime(),is8601dt.) as tstamp does work&amp;nbsp; the datetime value as an integer stored as a character can be used within a variable and returns the correct value&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Dec 2014 18:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149468#M39448</guid>
      <dc:creator>blom0344</dc:creator>
      <dc:date>2014-12-13T18:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149469#M39449</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My example is simply some &lt;STRONG&gt;testcode&lt;/STRONG&gt; to check differences and since it is executed within the same program , there is little reason for&amp;nbsp; a difference of 11592 seconds.&amp;nbsp;&amp;nbsp; The value itself is not stored as the datetime() value, but some sort of rounded figure.&amp;nbsp; But why?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I find SAS quite exhausting at times, but that may be due to working with relational databases for 20 years&amp;nbsp; &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Calling the start_time&amp;nbsp; variable as you define it does not work&amp;nbsp;&amp;nbsp; @start_time&amp;nbsp; is not recognized,&amp;nbsp; so perhaps the entire code needs to be within a macro?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Dec 2014 18:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149469#M39449</guid>
      <dc:creator>blom0344</dc:creator>
      <dc:date>2014-12-13T18:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149470#M39450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Well, I believe that without a PUT and a bigger format for the second SQL where you create the macro variables, you will see scientific notation for the big timestamp numbers, as shown in my 1st screen shot. But you can fix that by using an explicit PUT with a bigger format when you create the macro variables.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;However, your bigger problem is that your final PROC SQL does not make sense. Since I ran the program on a different day/time, I have a different timestamp than your program. But my second screen shot illustrates your problem. I would expect more than just the issue you note. With a bigger format, I do see the correct values in the macro variables. And, I can replicate your error message as shown in my second screen shot, because your second SELECT statement is incorrect. WORK.START_FALNR already has all the variables and values you want. I don't understand what the purpose of &amp;amp;max_hits, &amp;amp;process1 and &amp;amp;process2 in your final SQL.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; Your issue is NOT that you are unable to store the value, your issue is that the lack of a format caused the incorrect storage of the value. If you used SQL similar to this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;proc sql;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;create table work.is_this_what_you_want as&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;&amp;nbsp; select *, "&amp;amp;max_hits" as mac_max, "&amp;amp;process1" as mac_p1,&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;amp;process2" as mac_p2, "&amp;amp;tstamp" as mac_ts&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;&amp;nbsp; from work.start_falnr;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;quit;&lt;/STRONG&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;proc print data=work.is_this_what_you_want;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;Then you would get something similar to my 3rd screen shot (with different timestamp values, of course). And the only differences are attributable to rounding and formatting. So you could fix minor differences by rounding and/or using the INPUT function to convert the macro variables to numbers. Remember that Macro variables are ALWAYS text, they are ALWAYS treated as text. A reference to a macro variable has to be used with correct syntax. For example, this SQL can be executed:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; create table work.new as&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; select name, 99 &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; from sashelp.class;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc print data=work.new;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;but it results in the number 99 being assigned the column name of&amp;nbsp; _TEMA001 in WORK.NEW. But the SQL step below creates a new column called NEWVAR and the value for NEWVAR is 99 on every row. Since these examples use SASHELP.CLASS, you should be able to run them easily.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; create table work.new2 as&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; select name, 99 as newvar&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; from sashelp.class;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc print data=work.new2;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; So although you *CAN* use a numeric constant of 99 or 238 in a query, it doesn't make sense. And, the reason you got the error message on the timestamp was that there were illegal characters in the field and the ERROR message is telling you that you need a quoted string. You can replicate the error message without using macro variables by trying to run this code and I've included a 4th screen shot that shows the exact same error message that you got when you tried to use your unquoted macro variable:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; create table work.new3 as&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; select name, T99:99:99&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; from sashelp.class;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc print data=work.new3;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; My recommendation is that you clarify what your ultimate goal is, rethink how you make the macro variables and possibly rework your 3rd SQL query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10788i330A0A90328B07E1/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="baseball2_bad_select.png" title="baseball2_bad_select.png" /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10789iC95CBC88A9DD25DD/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="baseball4_unquoted_string_in_select.png" title="baseball4_unquoted_string_in_select.png" /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10790i835002967B77F36D/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="baseball3_good_select.png" title="baseball3_good_select.png" /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10791i1300F9F8449E114C/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="baseball_question1.png" title="baseball_question1.png" /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Dec 2014 18:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149470#M39450</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2014-12-13T18:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149471#M39451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay,let me clarify,&amp;nbsp; I put up some code at home , based on the student version on VMWARE and the available tables. (As mentioned)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The actual program I'm working on I cannot access from home, hence the example(s) from VMWARE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The actual idea is to store the timestamp from the beginning of the process (it takes about 3 minutes to run from begin to end) and then add the timestamp for reporting purposes to the resulting reporting table. (at the end)&lt;/P&gt;&lt;P&gt;The concept of applying a format is not easily adopted after working 20 year with each and every possible relational database, but I think that Cynthia really made it very clear.&amp;nbsp; Thanks for your feedback !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Dec 2014 18:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149471#M39451</guid>
      <dc:creator>blom0344</dc:creator>
      <dc:date>2014-12-13T18:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149472#M39452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your values are truncated because you used PROC SQL to generate the macro variables. &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;If you do not tell it otherwise PROC SQL will used BEST12. to display (and hence convert to macro variables) numeric values. I&lt;/SPAN&gt;f you are pulling a value from an dataset variable then use the FORMAT= modifier to tell SAS how to convert the number to a string to store into the macro variable. For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;select stored_time format=best32. into :mymacrovar from mytable ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you just want to generate a macro variable for the current DATETIME() then there is no need to write any SQL code.&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Note that it does not make any sense to use PROC SQL because you are not manipulating any datasets. &lt;/SPAN&gt;Most DMBS have tricks to allow you do this using SQL (like select ... from dual in Oracle) because SQL is the only language they have.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to create and manipulate macro variable just use %LET and macro functions. &lt;/P&gt;&lt;P&gt;For example try this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let now=%sysfunc(datetime());&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put Raw Datetime&amp;nbsp; =&amp;amp;now;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put ..............= %sysfunc(putn(&amp;amp;now,datetime24.5));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put Seconds&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = %sysfunc(round(&amp;amp;now,1)) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put ..............= %sysfunc(round(&amp;amp;now,1),datetime24.5);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put Tenths Seconds= %sysfunc(round(&amp;amp;now,.1)) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put ..............= %sysfunc(round(&amp;amp;now,.1),datetime24.5);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put Minutes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = %sysfunc(round(&amp;amp;now,60)) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put ..............= %sysfunc(round(&amp;amp;now,60),datetime24.5);&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Dec 2014 19:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149472#M39452</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-12-13T19:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149473#M39453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Tom, thanks for your reply.&amp;nbsp; My code was merely a random example.&amp;nbsp; The actual code does require the Proc SQL, so another SAS expert suggested the select into&amp;nbsp; option. Thanx also for the examples offered&amp;nbsp; !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Dec 2014 20:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149473#M39453</guid>
      <dc:creator>blom0344</dc:creator>
      <dc:date>2014-12-13T20:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149474#M39454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I observe SQL defaulting to BEST8. The DATA step language uses BEST12.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; demo ;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;numvar = constant(&lt;SPAN style="color: #800080;"&gt;'pi'&lt;/SPAN&gt;) ;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #0000ff;"&gt;put&lt;/SPAN&gt; numvar ;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; color: #0000ff;"&gt;run&lt;SPAN style="color: #000000;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; color: #000080;"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;sql&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;noprint&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #0000ff;"&gt;select&lt;/SPAN&gt; numvar &lt;SPAN style="color: #0000ff;"&gt;into&lt;/SPAN&gt; : macrovar &lt;SPAN style="color: #0000ff;"&gt;from&lt;/SPAN&gt; demo ;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #0000ff;"&gt;%put&lt;/SPAN&gt; &amp;amp;macrovar ;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; color: #000080;"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Dec 2014 16:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149474#M39454</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2014-12-14T16:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149475#M39455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It might be a default format problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data demo ;&lt;/P&gt;&lt;P&gt;numvar = constant('pi') ;&lt;/P&gt;&lt;P&gt;put numvar ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;proc sql noprint ;&lt;/P&gt;&lt;P&gt;select numvar &lt;STRONG&gt;format=best12.&lt;/STRONG&gt; into : macrovar from demo ;&lt;/P&gt;&lt;P&gt;%put &amp;amp;macrovar ;&lt;/P&gt;&lt;P&gt;quit ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Dec 2014 14:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/149475#M39455</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-12-15T14:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/253358#M56887</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm facing the same issue. Actually i'm trying to store datetime value in another variable.&lt;/P&gt;&lt;P&gt;can anyone assist me on the same issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm mentioning an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;Sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;Create&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;Table&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; Work.LastUpdateTable1 &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;Select&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'AccountBase'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; Memname, &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;Max(UpdateTime) &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt; LastUpdatedDate_SAS&lt;/STRONG&gt;&lt;/FONT&gt;, Count(Account_ID) &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; NOBS_SAS &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;From&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; Source.AccountBase;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;Quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Data Set:- &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;UpdateTime: 19SEP2015:02:50:45&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Output:- Coming&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;LastUpdateDate_SAS: 1771295413&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12331i4FE33BB04554A0F2/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="DataSet.png" title="DataSet.png" /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12332iE5E608A52DF9EE73/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Output.png" title="Output.png" /&gt;</description>
      <pubDate>Tue, 01 Mar 2016 07:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/253358#M56887</guid>
      <dc:creator>SKG</dc:creator>
      <dc:date>2016-03-01T07:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/718928#M80171</link>
      <description>Thank you! I just spent an hour trying to figure out why my datetime macro variable was showing the wrong day and time, and this fixed it.</description>
      <pubDate>Fri, 12 Feb 2021 16:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/718928#M80171</guid>
      <dc:creator>Mike_B</dc:creator>
      <dc:date>2021-02-12T16:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: unable to store datetime value in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/718933#M80172</link>
      <description>&lt;P&gt;With a modern version of SAS you could add the TRIMMED keyword to make sure the generated macro variable did not contain leading spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's make a sample dataset with a datetime variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  start = datetime();
  format start datetime19. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's query that to get the raw number of seconds since 1960 into a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select start format=32. into :start trimmed from test;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;20    %put &amp;amp;=start;
START=1928747688
&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/unable-to-store-datetime-value-in-a-macro-variable/m-p/718933#M80172</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-12T16:16:18Z</dc:date>
    </item>
  </channel>
</rss>

