<?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 Store Date in Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675831#M203663</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to store the date in a variable which I want use in other case later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below you will find my code. The output of variblae StartDate_OUT is "&lt;STRONG&gt;StartDate=.&lt;/STRONG&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I try to write &lt;STRONG&gt;%LET StartDate_OUT = date(); &lt;/STRONG&gt;I get an syntax error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where is my mistake?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
	format StartDate mmddyy10.;
	StartDate = date();
	%LET StartDate_OUT = StartDate=; 
run;

data _NULL_;
	PUT &amp;amp;StartDate_OUT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thanks,&lt;/P&gt;
&lt;P&gt;Sascha&lt;/P&gt;</description>
    <pubDate>Tue, 11 Aug 2020 06:55:04 GMT</pubDate>
    <dc:creator>SaschaD</dc:creator>
    <dc:date>2020-08-11T06:55:04Z</dc:date>
    <item>
      <title>Store Date in Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675831#M203663</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to store the date in a variable which I want use in other case later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below you will find my code. The output of variblae StartDate_OUT is "&lt;STRONG&gt;StartDate=.&lt;/STRONG&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I try to write &lt;STRONG&gt;%LET StartDate_OUT = date(); &lt;/STRONG&gt;I get an syntax error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where is my mistake?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
	format StartDate mmddyy10.;
	StartDate = date();
	%LET StartDate_OUT = StartDate=; 
run;

data _NULL_;
	PUT &amp;amp;StartDate_OUT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thanks,&lt;/P&gt;
&lt;P&gt;Sascha&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 06:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675831#M203663</guid>
      <dc:creator>SaschaD</dc:creator>
      <dc:date>2020-08-11T06:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Store Date in Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675834#M203666</link>
      <description>&lt;P&gt;Replace line&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET StartDate_OUT = StartDate=; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symput('StartDate_Out', startdate);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
	PUT &amp;amp;StartDate_OUT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you can check the value of the macro variable by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put StartDate_Out = &amp;amp;StartDate_OUT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Check the log; The number displayed is the sas value of the date, i.e. the days past since 01JAN1060.&amp;nbsp; In a datastep, use format to display this number in a required format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 07:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675834#M203666</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-11T07:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: Store Date in Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675838#M203669</link>
      <description>startydate?</description>
      <pubDate>Tue, 11 Aug 2020 07:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675838#M203669</guid>
      <dc:creator>Norman21</dc:creator>
      <dc:date>2020-08-11T07:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Store Date in Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675839#M203670</link>
      <description>&lt;P&gt;Sorry for the typo. Post was edited.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 07:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675839#M203670</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-11T07:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Store Date in Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675841#M203672</link>
      <description>&lt;P&gt;Storing formatted dates in macro-variables is not recommended if you plan to use the variable in comparisons with dataset-variables, because even if the same format is applied to the dataset-variable, the value is still a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global StartDate;
%let StartDate = %sysfunc(today());
%put &amp;amp;=StartDate;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Aug 2020 08:16:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675841#M203672</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-11T08:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Store Date in Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675866#M203685</link>
      <description>&lt;P&gt;I assume that what you want is to get today's date into the&amp;nbsp;StartDate_OUT macro variable, in the format MMDDYY10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is simply accomplished with %SYSFUNC:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let StartDate_OUT=%sysfunc(today(),mmddyy10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 10:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675866#M203685</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-08-11T10:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Store Date in Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675868#M203687</link>
      <description>&lt;P&gt;Your code does not result in a syntax ERROR:&lt;/P&gt;
&lt;PRE&gt; 73         data _NULL_;
 74           format StartDate mmddyy10.;
 75           StartDate = date();
 76           %LET StartDate_OUT = StartDate=;
 77         run;
 
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 78         
 79         data _NULL_;
 80           PUT &amp;amp;StartDate_OUT;
 81         run;
 
 NOTE: Variable StartDate is uninitialized.
 StartDate=.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;But you get a NOTE. Will come to that later.&lt;/P&gt;
&lt;P&gt;Your first data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
  format StartDate mmddyy10.;
  StartDate = date();
  %LET StartDate_OUT = StartDate=; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is equivalent to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET StartDate_OUT = StartDate=;

data _NULL_;
  format StartDate mmddyy10.;
  StartDate = date();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because the macro processor resolves macro statements when they are encountered in the code, before the data step compiler kicks in, compiles the data step code, and runs it.&lt;/P&gt;
&lt;P&gt;So you now have assigned this text to the macro variable:&lt;/P&gt;
&lt;PRE&gt;StartDate=&lt;/PRE&gt;
&lt;P&gt;When the macro processor finds this macro variable in the next data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
  PUT &amp;amp;StartDate_OUT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it replaces the macro variable with the text stored in it, so you get&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
  PUT StartDate=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is valid data step syntax, but references a &lt;EM&gt;data step variable&lt;/EM&gt;&amp;nbsp;(startdate) that does not yet exist, so it is created with a missing value, causing the "uninitialized" NOTE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep in mind:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the macro processor is a &lt;EM&gt;text replacement&lt;/EM&gt; engine used to make &lt;EM&gt;writing code&lt;/EM&gt; easier&lt;/LI&gt;
&lt;LI&gt;macro triggers are resolved immediately&lt;/LI&gt;
&lt;LI&gt;macro statements do not have access to data step variables&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 11 Aug 2020 10:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675868#M203687</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-11T10:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Store Date in Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675869#M203688</link>
      <description>&lt;P&gt;Also see Maxim 28. Values stored in macro variables for later use in code rarely need a format. Formatting is only needed if the macro variable in question is used for human-readable display (e-g. in the text of a TITLE statement). In all other cases, the raw values are easier to use when referencing the macro variable.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 10:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-Date-in-Variable/m-p/675869#M203688</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-11T10:37:24Z</dc:date>
    </item>
  </channel>
</rss>

