<?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: SAS Macro code: in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446547#M283249</link>
    <description>Hi Patrick&lt;BR /&gt;If I know how this code works, the I would'nt have wasted everyone time to answer&lt;BR /&gt;The question, don't worry I will keep on trying and try to understand the documentation&lt;BR /&gt;As well, hopefully I will make something it of it in a months time...&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Tk&lt;BR /&gt;</description>
    <pubDate>Sun, 18 Mar 2018 08:48:37 GMT</pubDate>
    <dc:creator>bondtk</dc:creator>
    <dc:date>2018-03-18T08:48:37Z</dc:date>
    <item>
      <title>SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446539#M283245</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am quite new to SAS macros.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help if someone could explain me this code in layman's term , step by step code explanation so that I could develop&lt;/P&gt;&lt;P&gt;some understanding how it works.&amp;nbsp; This macro is to define start date and end date and using to extract data and also&lt;/P&gt;&lt;P&gt;to create datestamp for files names as well.&amp;nbsp; Please advise in simple way as I am not very experienced in this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;TK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*startmonth - 'DDMMYYY'd*/&lt;/P&gt;&lt;P&gt;/*datestamp = YYYYMM*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; startdt = 01NOV2016;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; finishdt = 01AUG2017;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; datestamp = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(intnx(month,"&amp;amp;finishdt"d,0,b),year4.)&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(putn(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(intnx(month,"&amp;amp;finishdt"d,0,b),month3.),z2.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; extract(start,finish);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; enddate = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(intnx(month,"&amp;amp;finish."d,0,b),date9.);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; datestamp = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(intnx(month,"&amp;amp;finish"d,0,b),year4.)&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(putn(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(intnx(month,"&amp;amp;finish"d,0,b),month3.),z2.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;call symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'startmonth'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,compress(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"'"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;||&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;start."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;||&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"'d"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;call symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'endmonth'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,compress(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"'"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;||&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;finish."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;||&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"'d"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;startmonth.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;endmonth.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;enddate.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;datestamp.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;data tk.application_extract_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;datestamp.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;set sastrain.application_extract;&lt;/P&gt;&lt;P&gt;where &amp;amp;startmonth &amp;lt;= datepart(d_entry) &amp;lt;= &amp;amp;endmonth;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; extract;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;%&lt;STRONG&gt;&lt;I&gt;extract&lt;/I&gt;&lt;/STRONG&gt;(&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;startdt.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;finishdt.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 06:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446539#M283245</guid>
      <dc:creator>bondtk</dc:creator>
      <dc:date>2018-03-18T06:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446540#M283246</link>
      <description>&lt;P&gt;Instead of those eye-soring sysfunc avalanches, do your date calculations in the data step, where they belong. It's WAY easier to debug them there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A YYYYMM month stamp can be created in one step with the yymmn6. format.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 06:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446540#M283246</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-18T06:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446544#M283247</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I asked this question if someone can elaborate in layman term to make me understand&lt;BR /&gt;This code first.&lt;BR /&gt;&lt;BR /&gt;And if there is an easy way to write this code to achieve the same result then it&lt;BR /&gt;It will be very handy to know.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Tk&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 18 Mar 2018 07:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446544#M283247</guid>
      <dc:creator>bondtk</dc:creator>
      <dc:date>2018-03-18T07:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446545#M283248</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/137395"&gt;@bondtk&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I believe you understand already what this macro does: You pass in two values and then based on these values the macro creates a bunch of macro variables and then uses these macro variables in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anything further: That's code and if you want to understand it then there is documentation where you can lookup all of the statements and functions used. On this low level there isn't any layman's language anymore. It's code and you need to skill-up and become the experts if you want to understand.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 08:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446545#M283248</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-18T08:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446547#M283249</link>
      <description>Hi Patrick&lt;BR /&gt;If I know how this code works, the I would'nt have wasted everyone time to answer&lt;BR /&gt;The question, don't worry I will keep on trying and try to understand the documentation&lt;BR /&gt;As well, hopefully I will make something it of it in a months time...&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Tk&lt;BR /&gt;</description>
      <pubDate>Sun, 18 Mar 2018 08:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446547#M283249</guid>
      <dc:creator>bondtk</dc:creator>
      <dc:date>2018-03-18T08:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446574#M283250</link>
      <description>&lt;P&gt;Let's break it down. First this block:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startdt = 01NOV2016;
%let finishdt = 01AUG2017;
%let datestamp = %sysfunc(intnx(month,"&amp;amp;finishdt"d,0,b),year4.)%sysfunc(putn(%sysfunc(intnx(month,"&amp;amp;finishdt"d,0,b),month3.),z2.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is setting two macro variables dates represented in DATE9 format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then it does a really convoluted process to get the YEAR and MONTH part of the second one and put them back together in YYYYMON order.&amp;nbsp; The %sysfunc() macro function lets you use data step functions in macro code. The optional second argument let's you control what format SAS uses to generate the string that is returned.&amp;nbsp; The INTNX() function let's you calculate a change in date.&amp;nbsp; The "..."d is how to represent a date literal. The value inside the quotes must be something the DATE informat will recognize.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the first %sysfunc() call converts FINISHDT to a four digit year.&amp;nbsp; You could have just done %substr(&amp;amp;finishdt,6), but that would only work if FINISHDT is formatted using exactly 9 characters. The function call would work with other equivalent representations like 1AUG2017, 1AUG17,01-AUG-2017, etc.&amp;nbsp; The second one is getting the two digit month number.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the INTNX() function calls are not really doing anything since you are just moving by intervals of zero length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not just replace with:a single function call?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datestamp=%sysfunc(putn("&amp;amp;finishdt"d,yymmn6.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what does the macro do?&amp;nbsp; The %MACRO and %MEND statements mark the beginning and ending of the macro definition. The macro is defined to take two parameters and can both be passed by position if you want.&amp;nbsp; &amp;nbsp;When the macro starts the values of the local macro variables START and FINISH will be set to the values that were passed when the macro was called.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So these two statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let enddate = %sysfunc(intnx(month,"&amp;amp;finish."d,0,b),date9.);
%let datestamp = %sysfunc(intnx(month,"&amp;amp;finish"d,0,b),year4.)%sysfunc(putn(%sysfunc(intnx(month,"&amp;amp;finish"d,0,b),month3.),z2.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The second is like the code above and could be simplified in a similar way. The first just converts any valid date literal value in the input parameter FINISH into DATE9 format and store it in the macro variable ENDATE.&amp;nbsp; Looks like a little format standardization?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('startmonth',compress("'"||"&amp;amp;start."||"'d"));
  call symputx('endmonth',compress("'"||"&amp;amp;finish."||"'d"));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Looks like an attempt to create date literals from the input parameters.&amp;nbsp; Perhaps the person that wrote this didn't understand that SAS doesn't care whether you use single quotes or double quotes in date literals?&amp;nbsp; This could just as easily be done like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startmonth = "&amp;amp;start."d ;
%let endmonth = "&amp;amp;finish."d ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Next are just code to dump values to the log.&lt;/P&gt;
&lt;P&gt;Then finally it looks like the macro gets to doing some actual work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tk.application_extract_&amp;amp;datestamp.;
  set sastrain.application_extract;
  where &amp;amp;startmonth &amp;lt;= datepart(d_entry) &amp;lt;= &amp;amp;endmonth;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So here they are making a dataset where the output name includes the 6 digit YYYYMM formatted date value and the values selected fall within the range of date defined by the input parameters.&lt;/P&gt;
&lt;P&gt;So the whole macro can simply be reduced to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro extract(start,finish);
data tk.application_extract_%sysfunc(putn("&amp;amp;finish"d,yymmn6)) ;
  set sastrain.application_extract;
  where "&amp;amp;start"d  &amp;lt;= datepart(d_entry) &amp;lt;= "&amp;amp;finish"d;
run;
%mend extract;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 14:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446574#M283250</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-18T14:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446674#M283251</link>
      <description>&lt;P&gt;In addition to the fine explanation&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; gave you, there is no need to store dates (or datetimes) in macro variables in human-readable form, if you want to use them as values in code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('startdt',put(input('01NOV2016',date9.),best.));
call symputx('finishdt',put(input('01AUG2017',date9.),best.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then simplify your macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro extract(start,finish);
data tk.application_extract_%sysfunc(putn(&amp;amp;finish,yymmn6.));
  set sastrain.application_extract;
  where &amp;amp;start  &amp;lt;= datepart(d_entry) &amp;lt;= &amp;amp;finish;
run;
%mend extract;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and call it accordingly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%extract(&amp;amp;startdt,&amp;amp;finishdt)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: changed member reference to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 07:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446674#M283251</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-19T07:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446677#M283252</link>
      <description>&lt;P&gt;Hi Tom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for taking time and explain this to me in a very easy format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have changed the code as per your instructions and it worked..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code is :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let startdt = 01NOV2016;&lt;/P&gt;&lt;P&gt;%let finishdt = 01FEB2017;&lt;/P&gt;&lt;P&gt;%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; extract(start,finish);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let enddate = %sysfunc(intnx(month,"&amp;amp;finish."d,0,b),date9.);&lt;/P&gt;&lt;P&gt;%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let startmonth = "&amp;amp;start."d ;&lt;/P&gt;&lt;P&gt;%let endmonth = "&amp;amp;finish."d ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tk.application_extract_&amp;amp;datestamp.;&lt;/P&gt;&lt;P&gt;set sastrain.application_extract;&lt;/P&gt;&lt;P&gt;where &lt;STRONG&gt;"&amp;amp;start"d&lt;/STRONG&gt; &amp;lt;= datepart(d_entry) &amp;lt;= &lt;STRONG&gt;"&amp;amp;finish"d&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt; extract;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;extract&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;startdt.,&amp;amp;finishdt.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just need to ask few questions for my understanding and learning.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this code,&amp;nbsp; three variables are defined outside the macro, do we call them global variables as they are defined outside the macro,&amp;nbsp; I think the reason datestamp&lt;/P&gt;&lt;P&gt;Variable is defined outside the macro so we can use this datestamp to other codes in the same project whenever we create other files with same datestamp. So that means&lt;/P&gt;&lt;P&gt;Startdt and finishdate could be defined inside the macro or do they have to define outside the macro,&amp;nbsp; that’s first question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2nd question:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;04 variables are defined inside the macro, &amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;enddate variable is not used anywhere apart from the %put&amp;nbsp; function to see on the log so that can be removed , isn’t it ?&lt;/LI&gt;&lt;LI&gt;Startmonth and endmonth&amp;nbsp; variables in the macro , we use “&amp;amp;start.”d ,&amp;nbsp; so the reason was to define the date literal , and we need to&amp;nbsp; dot after the start and it has to be in double quotes.&lt;/LI&gt;&lt;LI&gt;Datestamp , I used the same way as it was outside the macro.&amp;nbsp; We use putn(“&amp;amp;finishdt”d, yymmn6.))..&amp;nbsp;&amp;nbsp;&amp;nbsp; we use putn &amp;nbsp;with finishdt to change it to numeric format?&amp;nbsp; Is it true? &amp;nbsp;%sysfunction is only used Within macro to able to use putn.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3rd question:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When we define the variable we use &amp;nbsp;&amp;nbsp;%let startmonth = "&amp;amp;start."d ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However when we use the where statement , we write as “&amp;amp;start”d&amp;nbsp; , no dot after the start, please advise on that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where &lt;STRONG&gt;"&amp;amp;start"d&lt;/STRONG&gt; &amp;lt;= datepart(d_entry) &amp;lt;= &lt;STRONG&gt;"&amp;amp;finish"d&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4th question:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I don’t need start date and only need the finish date so I can extract all data from the finish date&lt;/P&gt;&lt;P&gt;, can I write like this: and remove the startmonth variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let finishdt = 01FEB2018;&lt;/P&gt;&lt;P&gt;%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; extract(finish);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let enddate = %sysfunc(intnx(month,"&amp;amp;finish."d,0,b),date9.);&lt;/P&gt;&lt;P&gt;%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let endmonth = "&amp;amp;finish."d ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tk.application_extract_&amp;amp;datestamp.;&lt;/P&gt;&lt;P&gt;set sastrain.application_extract;&lt;/P&gt;&lt;P&gt;where datepart(d_entry) &amp;lt;= &lt;STRONG&gt;"&amp;amp;finish"d&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt; extract;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;extract&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;finishdt.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;question 5:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I have removed the&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data _&lt;EM&gt;null&lt;/EM&gt;_&amp;nbsp;&lt;/P&gt;&lt;P&gt;And symputx&amp;nbsp; routines from this code as it was not required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am just curious when do we require symput routines and why do we use it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And if you suggest any good book or any other source to understand macros , that will be really handy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please advise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your time.&lt;/P&gt;&lt;P&gt;TK&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 07:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446677#M283252</guid>
      <dc:creator>bondtk</dc:creator>
      <dc:date>2018-03-19T07:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446679#M283253</link>
      <description>&lt;P&gt;See comments:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startdt = 01NOV2016;
%let finishdt = 01FEB2017;

%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));
/* this statement is unnecessary, as it only creates a variable in the global
symbol table that is never used, as it will be overridden by the local one */

%macro extract(start,finish);

%let enddate = %sysfunc(intnx(month,"&amp;amp;finish."d,0,b),date9.);
/* &amp;amp;enddate is never used, so remove this statement */

%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));
/* the %sysfunc can be moved into the data statement */

%let startmonth = "&amp;amp;start."d ;
%let endmonth = "&amp;amp;finish."d ;
/* both of these are never used, so remove them also */

data tk.application_extract_&amp;amp;datestamp.;
set sastrain.application_extract;
where "&amp;amp;start"d &amp;lt;= datepart(d_entry) &amp;lt;= "&amp;amp;finish"d;
run;

%mend extract;

%extract(&amp;amp;startdt.,&amp;amp;finishdt.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Always strive to keep your code as simple as possible, see Maxim 37.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 07:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446679#M283253</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-19T07:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446680#M283254</link>
      <description>&lt;P&gt;Hi Kurt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So please advise what's wrong with this code: This code below worked fine , so why I have to use routines here&amp;nbsp; , what&lt;/P&gt;&lt;P&gt;advantage can symput gives me over this code below and frankly speaking I don't understand these routines anyway...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%let startdt = 01NOV2016;&lt;/P&gt;&lt;P&gt;%let finishdt = 01FEB2017;&lt;/P&gt;&lt;P&gt;%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; extract(start,finish);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/P&gt;&lt;P&gt;%let startmonth = "&amp;amp;start."d ;&lt;/P&gt;&lt;P&gt;%let endmonth = "&amp;amp;finish."d ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tk.application_extract_&amp;amp;datestamp.;&lt;/P&gt;&lt;P&gt;set sastrain.application_extract;&lt;/P&gt;&lt;P&gt;where &lt;STRONG&gt;"&amp;amp;start"d&lt;/STRONG&gt; &amp;lt;= datepart(d_entry) &amp;lt;= &lt;STRONG&gt;"&amp;amp;finish"d&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt; extract;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;extract&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;startdt.,&amp;amp;finishdt.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 07:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446680#M283254</guid>
      <dc:creator>bondtk</dc:creator>
      <dc:date>2018-03-19T07:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446682#M283255</link>
      <description>&lt;P&gt;I simply prefer to use data _null_ steps and call symput/symputx because it removes the need to think about all the quoting issues.&lt;/P&gt;
&lt;P&gt;Similarly, I prefer to have values in macro variables that are as simple as possible. Hence my post about using raw date/datetime values instead of formatted ones.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember, someone has to maintain the code in the future, and that someone may well be you, and you'll curse your former self for any unnecessary piece of code that makes your work harder.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 07:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446682#M283255</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-19T07:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446686#M283256</link>
      <description>&lt;P&gt;Hi Kurt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your comments:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the reason I used the&amp;nbsp; %let datestamp outside the macro as this variable will be used later on when I create other reports based on the&amp;nbsp;same data extract.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when you say to remove these 02,&amp;nbsp; I think we are using them with the where statement , don't we, please clarify.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt; startmonth &lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"&amp;amp;start."&lt;/SPAN&gt;&lt;SPAN&gt;d &lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt; endmonth &lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"&amp;amp;finish."&lt;/SPAN&gt;&lt;SPAN&gt;d &lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have removed the %enddate as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let startdt = 01NOV2016;&lt;/P&gt;&lt;P&gt;%let finishdt = 01FEB2017;&lt;/P&gt;&lt;P&gt;%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; extract(start,finish);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let startmonth = "&amp;amp;start."d ;&lt;/P&gt;&lt;P&gt;%let endmonth = "&amp;amp;finish."d ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tk.application_extract_&amp;amp;datestamp.;&lt;/P&gt;&lt;P&gt;set sastrain.application_extract;&lt;/P&gt;&lt;P&gt;where &lt;STRONG&gt;"&amp;amp;start"d&lt;/STRONG&gt; &amp;lt;= datepart(d_entry) &amp;lt;= &lt;STRONG&gt;"&amp;amp;finish"d&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt; extract;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;extract&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;startdt.,&amp;amp;finishdt.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 07:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446686#M283256</guid>
      <dc:creator>bondtk</dc:creator>
      <dc:date>2018-03-19T07:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446691#M283257</link>
      <description>&lt;P&gt;Is there any use of &amp;amp;startmonth or &amp;amp;endmonth? Answer: no. Therefore remove these unnecessary statements, they only create local macro variables that are never used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 08:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446691#M283257</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-19T08:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446694#M283258</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/137395"&gt;@bondtk&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Kurt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate your comments:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the reason I used the&amp;nbsp; %let datestamp outside the macro as this variable will be used later on when I create other reports based on the&amp;nbsp;same data extract.&lt;/P&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a valid reason. But it gives you even more reason to incorporate the %sysfunc into the data statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tk.application_extract_%sysfunc(putn(&amp;amp;finish,yymmn6.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as it removes the ambiguous use of the name datestamp that &lt;EM&gt;will&lt;/EM&gt; cause confusion sometime down the line.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 08:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446694#M283258</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-19T08:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446929#M283259</link>
      <description>&lt;P&gt;Hi Kurt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a valid reason. But it gives you even more reason to incorporate the %sysfunc into the data statement&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; tk&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;application_extract_&lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;putn&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;finish&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;yymmn6&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;as it removes the ambiguous use of the name datestamp that &lt;EM&gt;will&lt;/EM&gt; cause confusion sometime down the line.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;SPAN class="token punctuation"&gt;1.&amp;nbsp; isn't it better to write :&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;FONT face="Courier New" size="3"&gt;data tk.application_extract_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;datestamp.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;rather than replace the &amp;amp;datestamp with&amp;nbsp; %sysfunc(putn($finish, yymmn6.))&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;as datestamp will bring the same thing and easy to&amp;nbsp;apply as its already defined as variable and its a simple code&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;so I don't see any confusion about it.&amp;nbsp; Please clarify your confusion about it.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;EM&gt;2.&amp;nbsp; You mentioned to remove&lt;/EM&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;EM&gt;%let startmonth = "&amp;amp;start."d;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;EM&gt;%let endmonth =&amp;nbsp; "&amp;amp;finish."d;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;EM&gt;so I am confused as&amp;nbsp; I thought we are using them in the data statement :&amp;nbsp; Please clarify if that's not the case.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;data tk.application_extract_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;datestamp.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;set sastrain.application_extract;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;where &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;start"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;lt;= datepart(d_entry) &amp;lt;= &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;finish"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**************************************************&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have to write this code with global variable as datestamp which you can use anywhere in other programs.&lt;/P&gt;&lt;P&gt;How would you write it from start to finish.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; startdt = 01NOV2016;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; finishdt = 01FEB2017;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; datestamp = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; extract(start,finish);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; datestamp = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; startmonth = "&amp;amp;start."d ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; endmonth = "&amp;amp;finish."d ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;startmonth.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;endmonth.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;datestamp.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;data tk.application_extract_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;datestamp.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set sastrain.application_extract;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;where &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;start"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;lt;= datepart(d_entry) &amp;lt;= &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;finish"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; extract;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;%&lt;STRONG&gt;&lt;I&gt;extract&lt;/I&gt;&lt;/STRONG&gt;(&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;startdt.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;finishdt.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 20:33:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446929#M283259</guid>
      <dc:creator>bondtk</dc:creator>
      <dc:date>2018-03-19T20:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446936#M283260</link>
      <description>&lt;P&gt;If you have already created a macro variable named DATESTAMP with the value you want then there is no need to create it again inside the macro.&amp;nbsp; You could just reference the existing macro variable.&amp;nbsp; Or to make the macro more independent pass the value you already created into the macro as the value of another parameter.&amp;nbsp; Or even better pass into the macro the name of the dataset you want to build and generate the name to pass in the call to the macro using the macro variable you already created in the larger program.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%extract(start=&amp;amp;startdt.,finish=&amp;amp;finishdt.,out=tk.application_extract_&amp;amp;datestamp.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro code you posted is subsetting the data using the input parameters START and FINISH.&amp;nbsp; So there is no need to create new macro variables named STARTMONTH and ENDMONTH. The only thing that the macro does with STARTMONTH and ENDMONTH is write them to the SAS log.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 21:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/446936#M283260</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-19T21:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/447010#M283261</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;: I would never, ever use a macro variable declared outside the macro when the value should be derived from one of the macro parameters.&lt;/P&gt;
&lt;P&gt;Unless I had a severe masochistic streak, of course.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;if you use the macro in a program that does not have &amp;amp;datestamp, it crashes&lt;/LI&gt;
&lt;LI&gt;if global &amp;amp;datestamp is calculated from other values than those used in calling the macro, hilarious fun ensues.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;If one decides to use an extra variable for storing the yyyymm timestamp, then it&amp;nbsp;must be declared local to the macro, to avoid side-effects. Or you introduce it as an additional parameter, as you suggested.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 06:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/447010#M283261</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-20T06:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/447343#M283262</link>
      <description>&lt;P&gt;Ok Guys&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have simplified the code as much as possible and run it, it ran without any errors..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please advise if you are happy with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have removed the datestamp&amp;nbsp;variable inside the macro as I want to use datestamp with other programs as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; startdt = 01JAN2016;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; finishdt = 01FEB2017;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; datestamp = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(putn("&amp;amp;finishdt"d, yymmn6.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; extract(start,finish);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;data tk.application_extract_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;datestamp.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set sastrain.application_extract;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;where &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;startdt"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;lt;= datepart(d_entry) &amp;lt;= &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;finishdt"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; extract;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;%&lt;STRONG&gt;&lt;I&gt;extract&lt;/I&gt;&lt;/STRONG&gt;(&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;startdt.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;finishdt.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried both statements with where and both worked , don't know why, If you could clarify.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;where &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;start"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;lt;= datepart(d_entry) &amp;lt;= &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;finish"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;where &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;startdt"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;lt;= datepart(d_entry) &amp;lt;= &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;finishdt"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;see the difference in &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;"&amp;amp;start"d&amp;nbsp; and&amp;nbsp; "&amp;amp;startdt"d,&amp;nbsp; why these both are acceptable, don't know..&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;******************************************&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to ask you Kurt you mention about&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_&lt;/P&gt;&lt;P&gt;and the symputx&amp;nbsp; routines to do the same thing.&amp;nbsp; Please advise for my learning&lt;/P&gt;&lt;P&gt;in which circumstances symputx is necessary and whats the advantage of that as compared&lt;/P&gt;&lt;P&gt;to the code that I used, I am sure they do the same thing but whats the advantage of using symputx&lt;/P&gt;&lt;P&gt;and why do we use it and prefer over the other code, just need to understand the difference and usage&lt;/P&gt;&lt;P&gt;of these routines.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 08:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/447343#M283262</guid>
      <dc:creator>bondtk</dc:creator>
      <dc:date>2018-03-21T08:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/447349#M283263</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startdt = 01JAN2016;
%let finishdt = 01FEB2017;
%let datestamp = %sysfunc(putn("&amp;amp;finishdt"d, yymmn6.));

%macro extract(start,finish);
data tk.application_extract_&amp;amp;datestamp.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If datestamp should always be derived from finish, this is sloppy and bad programming, for reasons I have already stated.&lt;/P&gt;
&lt;P&gt;This is only valid if finish as supplied as a macro parameter and datestamp as a global macro variable have no fixed relationship.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where "&amp;amp;start"d &amp;lt;= datepart(d_entry) &amp;lt;= "&amp;amp;finish"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;vs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where "&amp;amp;startdt"d &amp;lt;= datepart(d_entry) &amp;lt;= "&amp;amp;finishdt"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;comes from the fact that in your macro &lt;EM&gt;call&lt;/EM&gt; you used startdt and finishdt as parameters, so the values are the same. If that is what it is planned to be, the whole macro definition is unnecessary, at least the parameters. (you might still create a macro if an identical piece of code is needed several times in your program)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding the use of data steps and symput/symputx:&lt;/P&gt;
&lt;P&gt;it allows me to create values with simple data step code, which (at least to me) is much easier (to create and to maintain) than doing it in macro code. The numerous problems that people encounter here on the communities when using macro language tells me that this is a valid point.&lt;/P&gt;
&lt;P&gt;Also keep in mind that I am speaking from the POV of ~20 years of SAS experience and the POV of a communities superuser, which should tell you something. After all that time, I still only use macro code &lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;when I absolutely have to&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 09:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/447349#M283263</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-21T09:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro code:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/447354#M283264</link>
      <description>&lt;P&gt;Hi Kurt&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your reply , appreciate it,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so if you have to write this code from start to finish , how would you write &amp;nbsp;it , say you are writing it in this macro format , how would you define the date stamp macros &amp;nbsp;as global &amp;nbsp;or local , please advise what would be your flow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i am asking these silly questions as its my first attempt to write any macro, so be patient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as far as the data steps and symput is concerned, that's way outside my scope at this stage, may be later on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;TK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 09:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-code/m-p/447354#M283264</guid>
      <dc:creator>bondtk</dc:creator>
      <dc:date>2018-03-21T09:59:16Z</dc:date>
    </item>
  </channel>
</rss>

