<?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: Macro reslove a datetime constant in the Macro definitation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-reslove-a-datetime-constant-in-the-Macro-definitation/m-p/649766#M194836</link>
    <description>&lt;P&gt;Your macro program is fine, it's just an issue of mismatched data type.&lt;/P&gt;
&lt;P&gt;Since variables date and air are numeric, you also have to supply numeric values to it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The parameters you are passing are already numeric, but if you enclose them in quotes it will be processed as a literal string (character).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Get rid of the double quotes and it should work.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if date =&amp;amp;a and air =&amp;amp;b;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just to note, you are working with a "date" constant (i.e. '01Jan1994'd), not&amp;nbsp; "date-time" (i.e. '01Jan1994:00:00:00'dt)&lt;/P&gt;</description>
    <pubDate>Fri, 22 May 2020 02:59:28 GMT</pubDate>
    <dc:creator>sustagens</dc:creator>
    <dc:date>2020-05-22T02:59:28Z</dc:date>
    <item>
      <title>Macro reslove a datetime constant in the Macro definitation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-reslove-a-datetime-constant-in-the-Macro-definitation/m-p/649755#M194835</link>
      <description>&lt;P&gt;Hi guys. I am new to the Macro, and a bit confuse about how macro resolve the date-time constant in keyword parameter.&amp;nbsp; This is my code. I want to give a date and number to a and b, and subset a sashelp.air first observation into a subset dataset. But I don't know what is wrong, I cannot resolve the datetime constant in my data step. Please help, thank you in advance&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro subsetting(a=,b=);

data subset;
set sashelp.air;
if date ="&amp;amp;a" and air ="&amp;amp;b";
run;
%mend;
%subsetting(a='01jan94'd,b=112);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 May 2020 01:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-reslove-a-datetime-constant-in-the-Macro-definitation/m-p/649755#M194835</guid>
      <dc:creator>shawn123</dc:creator>
      <dc:date>2020-05-22T01:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro reslove a datetime constant in the Macro definitation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-reslove-a-datetime-constant-in-the-Macro-definitation/m-p/649766#M194836</link>
      <description>&lt;P&gt;Your macro program is fine, it's just an issue of mismatched data type.&lt;/P&gt;
&lt;P&gt;Since variables date and air are numeric, you also have to supply numeric values to it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The parameters you are passing are already numeric, but if you enclose them in quotes it will be processed as a literal string (character).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Get rid of the double quotes and it should work.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if date =&amp;amp;a and air =&amp;amp;b;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just to note, you are working with a "date" constant (i.e. '01Jan1994'd), not&amp;nbsp; "date-time" (i.e. '01Jan1994:00:00:00'dt)&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 02:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-reslove-a-datetime-constant-in-the-Macro-definitation/m-p/649766#M194836</guid>
      <dc:creator>sustagens</dc:creator>
      <dc:date>2020-05-22T02:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro reslove a datetime constant in the Macro definitation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-reslove-a-datetime-constant-in-the-Macro-definitation/m-p/649767#M194837</link>
      <description>&lt;P&gt;Is SASHELP.AIR the DATE variable is a number type containing SAS DATE values formatted to display as&amp;nbsp;MONYY5.&amp;nbsp; The AIR variable is a number type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF and WHERE statements deal with the underlying date value.&amp;nbsp; A date value is the number of days since 01JAN1960.&amp;nbsp; A date value can be presented to the system as a date LITERAL.&amp;nbsp; The construct is&amp;nbsp;&lt;CODE&gt;"ddMONyy"D&lt;/CODE&gt;or&amp;nbsp;&lt;CODE&gt;"ddMONyyyy"D&lt;/CODE&gt;.&amp;nbsp; Some other constructs are similar variations such as&amp;nbsp;&lt;CODE&gt;"dd-MONyyyy"D&lt;/CODE&gt;and&amp;nbsp;&lt;CODE&gt;"dd-MON-yyyy"D&lt;/CODE&gt;.&amp;nbsp; Single quotes can be used in place of double quotes in a date literal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you are passing the macro a sequence of characters (nominally called a string in macro, but it is not a string like in C or Java) that represents a date literal when resolved in the context of source code of a DATA step programming statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The B parameter is being passed characters that represent a number when resolved in the context of programming source code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What this all means is that you should NOT double quote the resolution of either parameter A or parameter B.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the MPRINT session option to have macro generated code appear in the LOG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;%macro subsetting(a=,b=);

data subset;
set sashelp.air;
if date = &amp;amp;a and air =&amp;amp;b;
run;
%mend;

options mprint;

%subsetting(a='01jan94'd,b=112)
----- LOG -----
16   %subsetting(a='01jan94'd,b=112)
MPRINT(SUBSETTING):   data subset;
MPRINT(SUBSETTING):   set sashelp.air;
MPRINT(SUBSETTING):   if date = '01jan94'd and air =112;
MPRINT(SUBSETTING):   run;

NOTE: There were 144 observations read from the data set SASHELP.AIR.
NOTE: The data set WORK.SUBSET has 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 02:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-reslove-a-datetime-constant-in-the-Macro-definitation/m-p/649767#M194837</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-22T02:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro reslove a datetime constant in the Macro definitation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-reslove-a-datetime-constant-in-the-Macro-definitation/m-p/649774#M194841</link>
      <description>Thank you for the reply. Learn a lot!</description>
      <pubDate>Fri, 22 May 2020 04:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-reslove-a-datetime-constant-in-the-Macro-definitation/m-p/649774#M194841</guid>
      <dc:creator>shawn123</dc:creator>
      <dc:date>2020-05-22T04:32:00Z</dc:date>
    </item>
  </channel>
</rss>

