<?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: Date macro variable not resolving in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393528#M94781</link>
    <description>&lt;P&gt;Please avoid coding all in upcase, its makes code so much harder to read. &amp;nbsp;You can use the {i} above the post area to post code, it then keeps the indentaion and such like. &amp;nbsp;Macro and macro variables are all text, so you need to think about text, not numbers (which dates are), which is why its only good for text generation. &amp;nbsp;Something like:&lt;/P&gt;
&lt;PRE&gt;%let rptdt=01JAN2016;

data test;
...;
run;

proc sql;
  create table TNEW as
  select  *
  from    TEST
  where   DATES &amp;gt;= "&amp;amp;rptdt."d;
quit;&lt;/PRE&gt;
&lt;P&gt;So the text from the macro variable gets resolved inside the normal use for a date literal. &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Sep 2017 13:01:46 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-09-06T13:01:46Z</dc:date>
    <item>
      <title>Date macro variable not resolving in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393526#M94779</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need your help to resolve the date macro variable value,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data _null_;&lt;BR /&gt;DATE1='01JAN2016'd;&lt;BR /&gt;CALL SYMPUT ('RPTDT',"'" || PUT(DATE1,YYMMDD10.) ||"'");&lt;BR /&gt;RUN;&lt;BR /&gt;%PUT &amp;amp;RPTDT ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA TEST;&lt;BR /&gt;INPUT CHARV : $1. DATES :DATE9. ;&lt;BR /&gt;FORMAT DATES DATE9.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;A 01FEB2016&lt;BR /&gt;B 01DEC2016&lt;BR /&gt;C 03FEB2015&lt;BR /&gt;D 06JUN2014&lt;BR /&gt;E 09JUL2017&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC PRINT DATA=TEST ; RUN;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE TNEW AS&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;SELECT * FROM TEST&lt;BR /&gt;WHERE DATES &amp;gt;= &amp;amp;RPTDT.&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it's not working correctly, Please suggest solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to use this date macro variable in select and where statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 12:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393526#M94779</guid>
      <dc:creator>Lohia</dc:creator>
      <dc:date>2017-09-06T12:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro variable not resolving in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393528#M94781</link>
      <description>&lt;P&gt;Please avoid coding all in upcase, its makes code so much harder to read. &amp;nbsp;You can use the {i} above the post area to post code, it then keeps the indentaion and such like. &amp;nbsp;Macro and macro variables are all text, so you need to think about text, not numbers (which dates are), which is why its only good for text generation. &amp;nbsp;Something like:&lt;/P&gt;
&lt;PRE&gt;%let rptdt=01JAN2016;

data test;
...;
run;

proc sql;
  create table TNEW as
  select  *
  from    TEST
  where   DATES &amp;gt;= "&amp;amp;rptdt."d;
quit;&lt;/PRE&gt;
&lt;P&gt;So the text from the macro variable gets resolved inside the normal use for a date literal. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 13:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393528#M94781</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-06T13:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro variable not resolving in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393531#M94782</link>
      <description>&lt;P&gt;Hi Lohia&lt;/P&gt;
&lt;P&gt;The problem is that your macro variable contains a text string&amp;nbsp;with year, month and date, while your input data contains a sas date value. Just store the SAS date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data _null_;&lt;BR /&gt;DATE1='01JAN2016'd;&lt;BR /&gt;CALL SYMPUTX('RPTDT',DATE1);&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%PUT &amp;amp;RPTDT ;&lt;/P&gt;
&lt;P&gt;DATA TEST;&lt;BR /&gt;INPUT CHARV : $1. DATES DATE9. ;&lt;BR /&gt;FORMAT DATES DATE9.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;A 01FEB2016&lt;BR /&gt;B 01DEC2016&lt;BR /&gt;C 03FEB2015&lt;BR /&gt;D 06JUN2014&lt;BR /&gt;E 09JUL2017&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 13:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393531#M94782</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2017-09-06T13:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro variable not resolving in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393542#M94787</link>
      <description>&lt;P&gt;It what way is not working correctly? &amp;nbsp;Are you getting error messages? Just not matching the values you expect?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first step generated a character string literal with a date value formatted into YYYY-MM-DD format.&lt;/P&gt;
&lt;PRE&gt;2933  %PUT &amp;amp;RPTDT ;
'2016-01-01'&lt;/PRE&gt;
&lt;P&gt;So that will only work if the variable you are comparing to is also a character variable and its contents also look like date values with the same format. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your variable has actual date values in it then you need to compare to a date literal like&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;"01JAN2016"d&lt;/PRE&gt;
&lt;P&gt;or an actual number of days since 01JAN1960 like&lt;/P&gt;
&lt;PRE&gt;20454&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 13:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393542#M94787</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-06T13:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro variable not resolving in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393546#M94791</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/65745"&gt;@Lohia&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Need your help to resolve the date macro variable value,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data _null_;&lt;BR /&gt;DATE1='01JAN2016'd;&lt;BR /&gt;CALL SYMPUT ('RPTDT',"'" || PUT(DATE1,YYMMDD10.) ||"'");&lt;BR /&gt;RUN;&lt;BR /&gt;%PUT &amp;amp;RPTDT ;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Others have given you good advice. However it is completely unnecessary to use the format, this actually makes your life harder. Instead, use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
    call symputx('rptdt','01JAN2016'd);
run;&lt;/PRE&gt;
&lt;P&gt;and then later&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
    create table tnew as select * from test where dates &amp;gt;= &amp;amp;rptdt;
quit;
&lt;/PRE&gt;
&lt;P&gt;In general, you don't need date formats or datetime formats for coding. In fact, they are unnecessary (although there probably are exceptions). The place they are needed is&amp;nbsp;to display results, for example in a TITLE or LABEL statements, or the output from some PROC.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 13:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393546#M94791</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-06T13:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro variable not resolving in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393554#M94798</link>
      <description>&lt;P&gt;While you have many accurate suggestions, the simplest one hasn't appeared yet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code can be replaced:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data _null_;&lt;BR /&gt;DATE1='01JAN2016'd;&lt;BR /&gt;CALL SYMPUT ('RPTDT',"'" || PUT(DATE1,YYMMDD10.) ||"'");&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, simply use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let rptdt = '01JAN2016'd;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the rest of the code should be fine.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 13:56:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393554#M94798</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-06T13:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro variable not resolving in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393809#M94876</link>
      <description>Thank you everyone, i tried RWS method its working.&lt;BR /&gt;Initially i also tried the same but forgot to remove quotes from the date&lt;BR /&gt;Thats why when i'm applying the right method its showing me the error like not resolved "'2016-01-01'".&lt;BR /&gt;&lt;BR /&gt;Thanks a lot again..</description>
      <pubDate>Thu, 07 Sep 2017 10:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-variable-not-resolving-in-proc-sql/m-p/393809#M94876</guid>
      <dc:creator>Lohia</dc:creator>
      <dc:date>2017-09-07T10:02:53Z</dc:date>
    </item>
  </channel>
</rss>

