<?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: Create a date variable from macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384729#M91935</link>
    <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;data new;
     set old;
     date = "&amp;amp;date9"d;
     format date date9.;
run;
&lt;/PRE&gt;
&lt;P&gt;You were attempting to use a "date literal" value but missing that in basic syntax the way to use a data literal is "01JAN2017"d; The d at the end, no space after the quote, tells SAS to use this a date. Date literal must be in the form of ddMONyy or ddMONyyyy where dd is day of month, MON is three-letter abbreviation and yy or yyyy is either a 2 or 4 digit year. I recomment using the 4-digit to remove any confusion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Aug 2017 19:03:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-08-01T19:03:52Z</dc:date>
    <item>
      <title>Create a date variable from macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384726#M91934</link>
      <description>&lt;P&gt;I want to create a date variable in my program from a macro %LET statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET date9 01AUG2017;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set old;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date = &amp;amp;date9;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cant get this to work, I dont quite understand how the date9 is stored in SAS I think - adding a format statement also doesnt work. What am I missing here?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 18:56:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384726#M91934</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2017-08-01T18:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Create a date variable from macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384729#M91935</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;data new;
     set old;
     date = "&amp;amp;date9"d;
     format date date9.;
run;
&lt;/PRE&gt;
&lt;P&gt;You were attempting to use a "date literal" value but missing that in basic syntax the way to use a data literal is "01JAN2017"d; The d at the end, no space after the quote, tells SAS to use this a date. Date literal must be in the form of ddMONyy or ddMONyyyy where dd is day of month, MON is three-letter abbreviation and yy or yyyy is either a 2 or 4 digit year. I recomment using the 4-digit to remove any confusion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 19:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384729#M91935</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-01T19:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create a date variable from macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384730#M91936</link>
      <description>&lt;P&gt;Same suggestion as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, but you'll also have to correct your let statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%LET date9=01AUG2017;

data old;
  input x y;
  cards;
1 2
3 4
;

data new;
     set old;
     format date date9.;
     date = input("&amp;amp;date9",date9.);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 19:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384730#M91936</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-08-01T19:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create a date variable from macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384737#M91937</link>
      <description>&lt;P&gt;Thank you both! LET statement was a typo, both worked beautifully.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 19:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384737#M91937</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2017-08-01T19:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create a date variable from macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384738#M91938</link>
      <description>&lt;P&gt;And if you want today, you can use DATE() or TODAY()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Create a macro variable;
%let myDate = %sysfunc(today(), date9.);

*Display macro variable for testing;
%put &amp;amp;myDate;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Aug 2017 19:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384738#M91938</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-01T19:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create a date variable from macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384739#M91939</link>
      <description>&lt;P&gt;Hi, I noticed you have missed out an = sign in a %let statement. %let is a macro assignment statement just like a variable assignment statement in a datastep.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Secondly you can copy paste&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;solution&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Correction:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET date9&lt;STRONG&gt;=&lt;/STRONG&gt;01AUG2017;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 19:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-date-variable-from-macro/m-p/384739#M91939</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-08-01T19:09:48Z</dc:date>
    </item>
  </channel>
</rss>

