<?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: Creating macro for data in a specific date range in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389866#M25179</link>
    <description>&lt;P&gt;This is a very simple example, and really no macros or macro variables are needed here.&amp;nbsp;It could be that the real-life problem is more complex, and perhaps macros are needed, although even there I am somewhat skeptical that this needs to be done via a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the fix to your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let  macrovariablename = DATASET_DATE  BETWEEN '18aug2017'd AND '20aug2017'd;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Note that this does not belong inside PROC SQL.&lt;/P&gt;</description>
    <pubDate>Tue, 22 Aug 2017 15:57:13 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-08-22T15:57:13Z</dc:date>
    <item>
      <title>Creating macro to get data from a specific date range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389856#M25173</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to build a macro that would automate a date range of data for my query.&lt;/P&gt;&lt;P&gt;This macro would generate data for an entire week.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried the following but nothing works when I invoke my variable name in my query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;BR /&gt;%let &amp;nbsp;DATASET_DATE &amp;nbsp;BETWEEN '18aug2017'd AND '20aug2017'd;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any help would be great!!!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2017 15:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389856#M25173</guid>
      <dc:creator>sabjacs</dc:creator>
      <dc:date>2017-08-22T15:32:24Z</dc:date>
    </item>
    <item>
      <title>Creating macro for data in a specific date range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389858#M25178</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to build a macro that would automate a date range of data for my query.&lt;/P&gt;&lt;P&gt;This macro would generate data for an entire week.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried the following but nothing works when I invoke my variable name in my query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;BR /&gt;%let &amp;nbsp;DATASET_DATE &amp;nbsp;BETWEEN '18aug2017'd AND '20aug2017'd;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any help would be great!!!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2017 15:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389858#M25178</guid>
      <dc:creator>sabjacs</dc:creator>
      <dc:date>2017-08-22T15:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro to get data from a specific date range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389860#M25174</link>
      <description>To build a macro first develop working SAS code. &lt;BR /&gt;What does your working SAS code look like? What are you expecting your macro call to look like? &lt;BR /&gt;&lt;BR /&gt;Are you sure you need a macro?&lt;BR /&gt;&lt;BR /&gt;Here's an intro into macro programming that may be helpful:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;</description>
      <pubDate>Tue, 22 Aug 2017 15:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389860#M25174</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-22T15:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro to get data from a specific date range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389863#M25176</link>
      <description>&lt;P&gt;Hi Reeza,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yes I have a working code, its quite large and I dont want to go through it each time to change the dates, thats why I want to built a macro which I can easily update without going through all my codes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2017 15:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389863#M25176</guid>
      <dc:creator>sabjacs</dc:creator>
      <dc:date>2017-08-22T15:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro for data in a specific date range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389866#M25179</link>
      <description>&lt;P&gt;This is a very simple example, and really no macros or macro variables are needed here.&amp;nbsp;It could be that the real-life problem is more complex, and perhaps macros are needed, although even there I am somewhat skeptical that this needs to be done via a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the fix to your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let  macrovariablename = DATASET_DATE  BETWEEN '18aug2017'd AND '20aug2017'd;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Note that this does not belong inside PROC SQL.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2017 15:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389866#M25179</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-08-22T15:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro for data in a specific date range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389868#M25180</link>
      <description>&lt;P&gt;Show what the Proc SQL code without any macros would be.&lt;/P&gt;
&lt;P&gt;Then tell us which parts you are attempting to replace with macro values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example has several issues. One there is not data source for proc sql to operate on, there is no instruction as to what operation, such as Select or update or insert.&lt;/P&gt;
&lt;P&gt;Your Let statement is incomplete. There should be an = in there after the name of the macro variable.&lt;/P&gt;
&lt;P&gt;And placing %let statements in the middle of Proc or datastep code is poor practice. The macro values should be defined before the step that attempts to use them.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2017 15:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389868#M25180</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-22T15:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro to get data from a specific date range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389870#M25181</link>
      <description>&lt;P&gt;Then post skeleton code that you can test. Unfortunately your code is not close to correct.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2017 15:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389870#M25181</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-22T15:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro for data in a specific date range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389949#M25202</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/160176"&gt;@sabjacs&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to build a macro that would automate a date range of data for my query.&lt;/P&gt;
&lt;P&gt;This macro would generate data for an entire week.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried the following but nothing works when I invoke my variable name in my query&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc SQL;&lt;BR /&gt;%let &amp;nbsp;DATASET_DATE &amp;nbsp;BETWEEN '18aug2017'd AND '20aug2017'd;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Syntax for a Let statement is:&lt;/P&gt;
&lt;P&gt;%let macrovariablename = some sort of string values;&lt;/P&gt;
&lt;P&gt;You are missing the =. Since you do not show HOW you attempted to use the macro variable we have NO WAY to guess exactly which of a plethora of potential problems you participated in.&lt;/P&gt;
&lt;P&gt;If you cannot share your data and can't make a dummy set then use a SAS supplied data set. The code below creates a set with dates so I'll show a brief example using it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a short example of one way to pass a couple of dates into macro:&lt;/P&gt;
&lt;PRE&gt;%macro dummy (startdate=, enddate=);
/* pass macro variables as dates in date9. format*/

data work.dummy;
   do date= "&amp;amp;startdate"d to "&amp;amp;enddate"d;
      output;
   end;
   format date mmddyy10.;
run;
%mend;

%dummy(startdate= 15Feb2017, enddate= 4Mar2017);
&lt;/PRE&gt;
&lt;P&gt;Note that I pass a value without quotes and place the macro variable into a date literal with double quotes. Passing quotes as parameters is a common cause of confusing program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro dateselect( dsname=, startdate=, enddate=);
proc sql;
   create table work.dateselect as
   select *
   from &amp;amp;dsname
   where Date between "&amp;amp;Startdate"d and "&amp;amp;Enddate"d
   ;
quit;
%mend;
%dateselect (dsname=work.dummy,startdate= 25Feb2017, enddate= 1Mar2017);
&lt;/PRE&gt;
&lt;P&gt;Note that my Proc sql includes what it is doing (creating a table in this case) , selecting variables, designating a source data set&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then applying the where clause.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2017 17:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389949#M25202</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-22T17:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro for data in a specific date range</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389954#M25203</link>
      <description>thanks a lot @ ballardw the solution works&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Aug 2017 18:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-macro-to-get-data-from-a-specific-date-range/m-p/389954#M25203</guid>
      <dc:creator>sabjacs</dc:creator>
      <dc:date>2017-08-22T18:09:17Z</dc:date>
    </item>
  </channel>
</rss>

