<?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: data _null_ help on below code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899438#M355515</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a step-by-step explanation, it might help you to see what is happening if you write the step out to a data set, as per the below code. The original&amp;nbsp;&lt;FONT face="courier new,courier"&gt;data _null_&lt;/FONT&gt;&amp;nbsp;code simply means a data step will not be created from the data statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  yymmdd  = put(today(),YYMMDDn8.);                /* #1 current year, month &amp;amp; date formatted to have no separators     */
  hour    = put(hour(time()), z2.);                /* #2 current hour formatted to have leading zeros to a width of 2   */
  minute  = put(minute(time()), z2.);              /* #3 current minute formatted to have leading zeros to a width of 2 */
  cat     = cat(yymmdd,hour,minute,'00');          /* #4 concatenate previously created values and add '00' to the end  */
  runtime = compress(cat);                         /* #5 remove any undesired characters                                */
  call symput ('runtime',compress(trim(runtime))); /* #6 save the value of runtime as a macro variable                  */
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code produces a data set as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Amir_0-1697823903566.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88986iA5F1FD070ABCCDD4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Amir_0-1697823903566.png" alt="Amir_0-1697823903566.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your runtime value will likely be different, as it is dependant on when the code is run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#1 uses the &lt;FONT face="courier new,courier"&gt;today()&lt;/FONT&gt; function which returns today's date, and the &lt;FONT face="courier new,courier"&gt;put()&lt;/FONT&gt; function is used to format how the value is displayed based on the given format, which in this case is&amp;nbsp;YYMMDDn8., i.e., occupy a width of 8 with no separators.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#2 uses the &lt;FONT face="courier new,courier"&gt;time()&lt;/FONT&gt; function which returns the current time, then the &lt;FONT face="courier new,courier"&gt;hour()&lt;/FONT&gt; function to extract just the hour value, and then the &lt;FONT face="courier new,courier"&gt;put()&lt;/FONT&gt; function is used to format how the value is displayed based on the given format, which in this case is&amp;nbsp;z2., i.e., occupy a width of 2 using a leading zero ('0') if required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#3 uses the &lt;FONT face="courier new,courier"&gt;time()&lt;/FONT&gt; function which returns the current time, then the &lt;FONT face="courier new,courier"&gt;minute()&lt;/FONT&gt; function to extract just the minute value, and then the &lt;FONT face="courier new,courier"&gt;put()&lt;/FONT&gt; function is used to format how the value is displayed based on the given format, which in this case is&amp;nbsp;z2., i.e., occupy a width of 2 using a leading zero ('0') if required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#4 uses the &lt;FONT face="courier new,courier"&gt;cat()&lt;/FONT&gt; function to join all of the previously created strings together as well as '00' on the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#5 uses the &lt;FONT face="courier new,courier"&gt;compress()&lt;/FONT&gt; function to remove any undesired characters, but as there no characters specified to be removed then the default characters are removed - see further below for a note on the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#6 uses the &lt;FONT face="courier new,courier"&gt;call symput()&lt;/FONT&gt; routine to create a macro variable (first argument), with a value supplied in the second argument. In this case the macro variable has been given the same name as the program variable, i.e., "runtime". The use of &lt;FONT face="courier new,courier"&gt;compress()&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;trim()&lt;/FONT&gt; appear to be redundant here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need further help with the functions used then you can consult the documentation for&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/allprodslang/syntaxByType-function.htm" target="_blank" rel="noopener"&gt;General Functions Syntax Listed Alphabetically&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2023 18:07:35 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2023-10-20T18:07:35Z</dc:date>
    <item>
      <title>data _null_ help on below code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899425#M355511</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please explain me below code step by step&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;runtime = compress(cat((put(today(),YYMMDDn8.)),(put(hour(time()), z2.)),(put(minute(time()), z2.)),'00'));&lt;BR /&gt;call symput ('runtime',compress(trim(runtime)));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;SK&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 17:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899425#M355511</guid>
      <dc:creator>soujanyak</dc:creator>
      <dc:date>2023-10-20T17:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: data _null_ help on below code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899428#M355512</link>
      <description>&lt;P&gt;If you run it and then add&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;=runtime;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you will see that it is creating a macro variable named RUNTIME whose value is the current date and time, with seconds forced to zero, and all special characters removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there better ways to do this? Probably, but I haven't bothered to try to figure out a better way, primarily because I don't believe macro variables should have formatted values like this in most cases, and also I believe that datetime values should be handled as numeric rather than character strings that have to be pulled apart and then joined.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 17:23:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899428#M355512</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-20T17:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: data _null_ help on below code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899429#M355513</link>
      <description>&lt;P&gt;Okay I thought of a quick easy way to do this, that doesn't require the datetime value to be handled as a character string to be pulled apart and re-assembled. I still don't think in most cases macro variables should have formatted date/time values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format; /* Create picture format that produces the exact format desired for date/time values *?
    picture special low-high='%Y%0m%0d%0h%0M00' (datatype=datetime) ;
run;
data _null_;
    call symputx('runtime',put(datetime(),special.));
run;
%put &amp;amp;=runtime;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 17:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899429#M355513</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-20T17:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: data _null_ help on below code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899436#M355514</link>
      <description>&lt;P&gt;It's creating a timestamp.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Peter Crawford wrote a lovely paper about a tiny utility macro to create timestamps.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi31/038-31.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi31/038-31.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you change the default format to be closer to yours, it would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO now( fmt= b8601dt15 ) /DES= 'timestamp';
 %SYSFUNC( DATETIME(), &amp;amp;fmt )
%MEND now ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Use like:&lt;/P&gt;
&lt;PRE&gt;1    %MACRO now( fmt= b8601dt15 ) /DES= 'timestamp';
2     %SYSFUNC( DATETIME(), &amp;amp;fmt )
3    %MEND now ;
4
5    %put %now() ;
20231020T135021
6
7    %let runtime=%now() ;
8    %put &amp;amp;=runtime ;
RUNTIME=20231020T135021
&lt;/PRE&gt;
&lt;P&gt;Note the format is slightly different than yours.&amp;nbsp; It has&amp;nbsp; T to separate the date from the time, and includes the actual seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's handy to use when you want a timestamp for a footnote, or as part of an output file name, or whatever.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 17:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899436#M355514</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-10-20T17:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: data _null_ help on below code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899438#M355515</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a step-by-step explanation, it might help you to see what is happening if you write the step out to a data set, as per the below code. The original&amp;nbsp;&lt;FONT face="courier new,courier"&gt;data _null_&lt;/FONT&gt;&amp;nbsp;code simply means a data step will not be created from the data statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  yymmdd  = put(today(),YYMMDDn8.);                /* #1 current year, month &amp;amp; date formatted to have no separators     */
  hour    = put(hour(time()), z2.);                /* #2 current hour formatted to have leading zeros to a width of 2   */
  minute  = put(minute(time()), z2.);              /* #3 current minute formatted to have leading zeros to a width of 2 */
  cat     = cat(yymmdd,hour,minute,'00');          /* #4 concatenate previously created values and add '00' to the end  */
  runtime = compress(cat);                         /* #5 remove any undesired characters                                */
  call symput ('runtime',compress(trim(runtime))); /* #6 save the value of runtime as a macro variable                  */
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code produces a data set as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Amir_0-1697823903566.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88986iA5F1FD070ABCCDD4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Amir_0-1697823903566.png" alt="Amir_0-1697823903566.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your runtime value will likely be different, as it is dependant on when the code is run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#1 uses the &lt;FONT face="courier new,courier"&gt;today()&lt;/FONT&gt; function which returns today's date, and the &lt;FONT face="courier new,courier"&gt;put()&lt;/FONT&gt; function is used to format how the value is displayed based on the given format, which in this case is&amp;nbsp;YYMMDDn8., i.e., occupy a width of 8 with no separators.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#2 uses the &lt;FONT face="courier new,courier"&gt;time()&lt;/FONT&gt; function which returns the current time, then the &lt;FONT face="courier new,courier"&gt;hour()&lt;/FONT&gt; function to extract just the hour value, and then the &lt;FONT face="courier new,courier"&gt;put()&lt;/FONT&gt; function is used to format how the value is displayed based on the given format, which in this case is&amp;nbsp;z2., i.e., occupy a width of 2 using a leading zero ('0') if required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#3 uses the &lt;FONT face="courier new,courier"&gt;time()&lt;/FONT&gt; function which returns the current time, then the &lt;FONT face="courier new,courier"&gt;minute()&lt;/FONT&gt; function to extract just the minute value, and then the &lt;FONT face="courier new,courier"&gt;put()&lt;/FONT&gt; function is used to format how the value is displayed based on the given format, which in this case is&amp;nbsp;z2., i.e., occupy a width of 2 using a leading zero ('0') if required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#4 uses the &lt;FONT face="courier new,courier"&gt;cat()&lt;/FONT&gt; function to join all of the previously created strings together as well as '00' on the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#5 uses the &lt;FONT face="courier new,courier"&gt;compress()&lt;/FONT&gt; function to remove any undesired characters, but as there no characters specified to be removed then the default characters are removed - see further below for a note on the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#6 uses the &lt;FONT face="courier new,courier"&gt;call symput()&lt;/FONT&gt; routine to create a macro variable (first argument), with a value supplied in the second argument. In this case the macro variable has been given the same name as the program variable, i.e., "runtime". The use of &lt;FONT face="courier new,courier"&gt;compress()&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;trim()&lt;/FONT&gt; appear to be redundant here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need further help with the functions used then you can consult the documentation for&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/allprodslang/syntaxByType-function.htm" target="_blank" rel="noopener"&gt;General Functions Syntax Listed Alphabetically&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 18:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899438#M355515</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2023-10-20T18:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: data _null_ help on below code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899441#M355516</link>
      <description>&lt;P&gt;Super explanation, thanks a lot&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 18:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-null-help-on-below-code/m-p/899441#M355516</guid>
      <dc:creator>soujanyak</dc:creator>
      <dc:date>2023-10-20T18:19:18Z</dc:date>
    </item>
  </channel>
</rss>

