<?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: Improper resolution of macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889802#M351580</link>
    <description>&lt;P&gt;Thanks for the prompt reply.&lt;/P&gt;
&lt;P&gt;How do I&amp;nbsp; get the current date and time as YYYYMMDDHH:MM:SS&lt;/P&gt;</description>
    <pubDate>Fri, 18 Aug 2023 07:37:31 GMT</pubDate>
    <dc:creator>Sathya3</dc:creator>
    <dc:date>2023-08-18T07:37:31Z</dc:date>
    <item>
      <title>Improper resolution of macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889676#M351522</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datetime = %sysfunc(datetime(), datetime19.); /* Get current datetime */

/* Format datetime to "YYYYMMDDHHMM" format */
%let currdate = %sysfunc(inputn(&amp;amp;datetime, yymmddn8.6));

%put &amp;amp;currdate; /* Print the value of the macro variable */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Currdate is resolving to missing value with below warning . How to correct this and get the datetime value in &lt;CODE class=" language-sas"&gt;"YYYYMMDDHHMM" format&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Argument 2 to function inputn referenced by %sysfunc or %qsysfunc macro function is out of range.mathematical operations could not be performed during %sysfunc function execution.result of operations have been set to a missing value&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 14:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889676#M351522</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-08-17T14:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Improper resolution of macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889677#M351523</link>
      <description>&lt;P&gt;It always helps to LOOK AT the values of these macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datetime = %sysfunc(datetime(), datetime19.); /* Get current datetime */
%put &amp;amp;=datetime;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the log, you will see&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATETIME=17AUG2023:10:31:35&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so this is not in yymmddn8.6 format, and so by creating CURRDATE with the YYMMDDN8.6 format, you get nothing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a specific output format, do &lt;STRONG&gt;NOT&lt;/STRONG&gt; first assign a different format to it and then convert to another format, that makes no sense. Right at the start, assign the format you want it to have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let currdate= %sysfunc(datetime(), b8601dt.); /* Get current datetime */
%put &amp;amp;=currdate;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which produces this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;CURRTIME=20230817T105143&lt;BR /&gt;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 14:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889677#M351523</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-17T14:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Improper resolution of macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889678#M351524</link>
      <description>&lt;P&gt;Why not use the same technique you use to create &amp;amp;DATETIME?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;24   %let currdate = %sysfunc(datetime(),B8601DT19);
25   %put NOTE: &amp;amp;=currdate;
NOTE: CURRDATE=20230817T074257
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Aug 2023 14:44:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889678#M351524</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2023-08-17T14:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Improper resolution of macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889683#M351526</link>
      <description>&lt;P&gt;Your macro variables look like they are properly resolved.&lt;/P&gt;
&lt;P&gt;It is your CODE that is wrong.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no YYMMDDn8.6 informat.&amp;nbsp; &amp;nbsp;So you are saying to read 8 characters and imply a decimal point between the 3 and 4th character?&amp;nbsp; That leaves only 2 digits for the integer part of the value. How would that have anything to do with a DATE (or even a DATETIME) value?&amp;nbsp; And it definitely does not match the string in DDMONYY:HH:MM:SS style that you generated in the first statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want a DATETIME value?&amp;nbsp; Then just use :%sysfunc(datetime()) which will return the number of seconds since start of 1960. Which is what a DATETIME value is.&lt;/P&gt;
&lt;PRE&gt;213  %let datetime = %sysfunc(datetime());
214  %put &amp;amp;=datetime;
DATETIME=2007888574.838
&lt;/PRE&gt;
&lt;P&gt;Now what do you want to do with this number?&amp;nbsp; If you want to use it in calculations with other datetime values it works fine.&lt;/P&gt;
&lt;PRE&gt;220  %let datetime = %sysfunc(datetime());
221  %put Hours since start of 2023-08-16 = %sysfunc(intck(hour,"16AUG2023:00:00"dt,&amp;amp;datetime));
Hours since start of 2023-08-16 = 34
&lt;/PRE&gt;
&lt;P&gt;Do you want a STRING in YYMMDDHHMMSS style?&lt;/P&gt;
&lt;PRE&gt;224  %let datetime = %sysfunc(compress(%sysfunc(datetime(),e8601dt.),-T:));
225  %put &amp;amp;=datetime;
DATETIME=20230817105548
&lt;/PRE&gt;
&lt;P&gt;But what are you going to do with that STRING?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot use it as a datetime value since it is totally different (and many order of magnitude different) than the actual datetime value:&lt;/P&gt;
&lt;PRE&gt;242  %let datetime = %sysfunc(datetime());
243  %let ymdhs = %sysfunc(compress(%sysfunc(putn(&amp;amp;datetime,e8601dt.)),-T:));
244  %put datetime = %sysfunc(putn(&amp;amp;datetime,comma22.));
datetime =          2,007,889,322
245  %put ymdhs    = %sysfunc(putn(&amp;amp;ymdhs,comma22.));
ymdhs    =     20,230,817,110,202
&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Aug 2023 15:03:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889683#M351526</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-17T15:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Improper resolution of macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889800#M351579</link>
      <description>&lt;P&gt;Thanks for the prompt reply.&lt;/P&gt;
&lt;P&gt;How do I get T removed from the output and get the current date and time as YYYYMMDDHH:MM:SS&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 07:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889800#M351579</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-08-18T07:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: Improper resolution of macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889802#M351580</link>
      <description>&lt;P&gt;Thanks for the prompt reply.&lt;/P&gt;
&lt;P&gt;How do I&amp;nbsp; get the current date and time as YYYYMMDDHH:MM:SS&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 07:37:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889802#M351580</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-08-18T07:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: Improper resolution of macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889805#M351581</link>
      <description>&lt;P&gt;For this particular display, you need to roll your own format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture mydt
  low-high = "%Y%0m%0d%0H:%0M:%0S" (datatype=datetime)
;
run;

%let now = %sysfunc(datetime(),mydt.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I would recommend to use ISO standard formatting, either basic (B8601DT) or extended (E8601DT).&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 07:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/889805#M351581</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-18T07:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Improper resolution of macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/890023#M351653</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442456"&gt;@Sathya3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the prompt reply.&lt;/P&gt;
&lt;P&gt;How do I&amp;nbsp; get the current date and time as YYYYMMDDHH:MM:SS&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;shared already how to create this custom format. Question is why would you do this and not use a ISO compliant format.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Aug 2023 02:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/890023#M351653</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-19T02:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Improper resolution of macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/890040#M351666</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442456"&gt;@Sathya3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I get T removed from the output and get the current date and time as YYYYMMDDHH:MM:SS&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's just a text string, you can use the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/n0fcshr0ir3h73n1b845c4aq58hz.htm" target="_self"&gt;COMPRESS function&lt;/A&gt; to remove the letter T. But really, as discussed by others, use an ISO compliant format, rather than creating your own, that will be better for you and for everyone else who might have to use this data.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Aug 2023 09:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/890040#M351666</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-19T09:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Improper resolution of macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/890056#M351676</link>
      <description>&lt;P&gt;Just don't remove the colons.&lt;/P&gt;
&lt;PRE&gt;1847  %let e8601dt=%sysfunc(datetime(),e8601dt.);
1848  %put &amp;amp;=e8601dt;
E8601DT=2023-08-19T11:40:05
1849  %let want=%sysfunc(compress(%sysfunc(datetime(),e8601dt.),-T));
1850  %put &amp;amp;=want;
WANT=2023081911:40:05

&lt;/PRE&gt;
&lt;P&gt;But with no delimiter at all between the days and the hours it would be very difficult for humans to see that as a datetime string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you want a colon there?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1853  %let want=%sysfunc(translate(%sysfunc(compress(%sysfunc(datetime(),e8601dt.),-)),:,T));
1854  %put &amp;amp;=want;
WANT=20230819:11:44:57
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It might be clearer to build the string up from the datetime value instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1855  %let now=%sysfunc(datetime());
1856  %let want=%sysfunc(datepart(&amp;amp;now),yymmddn8.):%sysfunc(timepart(&amp;amp;now),tod8.);
1857  %put &amp;amp;=want;
WANT=20230819:11:47:11
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Aug 2023 15:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improper-resolution-of-macro-variable/m-p/890056#M351676</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-19T15:47:49Z</dc:date>
    </item>
  </channel>
</rss>

