<?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: Loop between two macro variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458418#M116340</link>
    <description>Can you elaborate this %include code in my scenario</description>
    <pubDate>Sun, 29 Apr 2018 03:41:21 GMT</pubDate>
    <dc:creator>suresh123</dc:creator>
    <dc:date>2018-04-29T03:41:21Z</dc:date>
    <item>
      <title>Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458318#M116287</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created below macro to generate few datasets based on date macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro pull(date);

proc sql;

create table new&amp;amp;date as&amp;nbsp;

select * from acct

where date=&amp;amp;date.;

quit;



%mend;&lt;/PRE&gt;&lt;P&gt;So if i want to create dataset for 20170101&amp;nbsp;&lt;SPAN&gt;20170201&amp;nbsp;20170301&amp;nbsp;20170401&amp;nbsp;20170501, all i can do is use below macro&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro pull(20170101)

%macro pull(20170201)

%macro pull(20170301)

%macro pull(20170401)

%macro pull(20170501)&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;What i am planning now is create two macro variables&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%let begin=20170101;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%let end =20170501;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and create datasets based on begin and end using loop. Is it possible to do that.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2018 09:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458318#M116287</guid>
      <dc:creator>suresh123</dc:creator>
      <dc:date>2018-04-28T09:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458320#M116289</link>
      <description>&lt;P&gt;1. Why do you want to split up your data like this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. You don't need a macro to do this. Do a google search for CALL EXECUTE Examples. That will get you in the right direction.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2018 09:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458320#M116289</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-04-28T09:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458322#M116291</link>
      <description>Splitting to see each month reports</description>
      <pubDate>Sat, 28 Apr 2018 09:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458322#M116291</guid>
      <dc:creator>suresh123</dc:creator>
      <dc:date>2018-04-28T09:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458323#M116292</link>
      <description>&lt;P&gt;This should help:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop(startdt,enddt);
 %local date;
 %do date=&amp;amp;startdt. %to &amp;amp;enddt.; 
  %if %substr(&amp;amp;date.,5,2)=13 %then %let date=%eval(&amp;amp;date-12+100); 
  proc sql;
   create table new&amp;amp;date. as 
   select * from acct
   where date=&amp;amp;date.;
  quit;
 %end;
%mend;         
%loop(201701,201703);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using intnx() is the proper way, but this is easier to understand and works just as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2018 09:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458323#M116292</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-04-28T09:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458324#M116293</link>
      <description>&lt;P&gt;And I agree&amp;nbsp; with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; btw.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2018 09:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458324#M116293</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-04-28T09:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458328#M116294</link>
      <description>&lt;P&gt;A non macro way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table dates as
   select distinct date
   from sashelp.stocks
   where "01jan2000"d &amp;lt;= date &amp;lt;= "01jan2001"d;
quit;

data callstack;
   set dates;
   code=cats("data Stocks_", put(date, date9.), "; set sashelp.stocks; where date= ", date, ";run;");
   call execute(code);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Apr 2018 09:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458328#M116294</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-04-28T09:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458331#M116296</link>
      <description>Is there any chance we can do it using do loop to create multiple datatsets between the dates</description>
      <pubDate>Sat, 28 Apr 2018 10:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458331#M116296</guid>
      <dc:creator>suresh123</dc:creator>
      <dc:date>2018-04-28T10:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458332#M116297</link>
      <description>&lt;P&gt;What do you want those data sets to contain?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2018 10:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458332#M116297</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-04-28T10:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458333#M116298</link>
      <description>whatever it there in datatset acct. So what i am trying to do is give start and end date as macro variable and pull records from from acct dataset and create seperate datasets for each month between start and end dates</description>
      <pubDate>Sat, 28 Apr 2018 10:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458333#M116298</guid>
      <dc:creator>suresh123</dc:creator>
      <dc:date>2018-04-28T10:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458343#M116301</link>
      <description>I dont want to use %macro or call execute....</description>
      <pubDate>Sat, 28 Apr 2018 12:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458343#M116301</guid>
      <dc:creator>suresh123</dc:creator>
      <dc:date>2018-04-28T12:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458355#M116306</link>
      <description>&lt;P&gt;You post a macro yourself in your question?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2018 14:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458355#M116306</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-04-28T14:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458357#M116307</link>
      <description>%let beg="01jan2000"d;&lt;BR /&gt;%let end="01jan2001"d;&lt;BR /&gt;%macro Test;&lt;BR /&gt;%do date=&amp;amp;beg. %to &amp;amp;end.;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table IPw_&amp;amp;date. as&lt;BR /&gt;select *&lt;BR /&gt;from sample&lt;BR /&gt;where date=&amp;amp;date. quit;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%Test;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 28 Apr 2018 14:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458357#M116307</guid>
      <dc:creator>suresh123</dc:creator>
      <dc:date>2018-04-28T14:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458370#M116318</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/207177"&gt;@suresh123&lt;/a&gt; wrote:&lt;BR /&gt;I dont want to use %macro or call execute....&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If is difficult to generate dataset names without using some type of code generation.&amp;nbsp;The third choice for code generation is to use a data step to write the code to a text file and then %include the file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set have ;
  by date ;
  where date between &amp;amp;start and &amp;amp;end ;
  file code ;
  if first.date then put .......... ;
run;
%include code;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A fourth way to dynamically generate dataset names is to use HASH objects.&amp;nbsp; But hash objects are limited to amount of data that can be stored in memory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WHY do you need separate dataset?&amp;nbsp; What value is being added by splitting the data into many separate files?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Apr 2018 16:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458370#M116318</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-28T16:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458405#M116330</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/207177"&gt;@suresh123&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;You wrote earlier "&lt;EM&gt;Splitting to see each month reports&lt;/EM&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please let us know the whole story? What do you intend to do with these monthly data sets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all this splitting data is only to support monthly reporting then there is a good chance that you don't need to split the data at all.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using By Group processing allows for creation of multiple reports with a single Proc call, is easier to code, maintain and also processes more efficiently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample code to illustrate the concept:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do i=1 to 20;
    date='01Jan2018'd+i-1;
    output;
  end;
  format date date9.;
  stop;
run;

%let startDt=05Jan2018;
%let endDt  =10Jan2018;

options nobyline;
title "Report for Date: #BYVAL(date)";
proc print data=have noobs;
  by date;
  var i date;
  where date between "&amp;amp;startDt"d and "&amp;amp;endDt"d;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Apr 2018 00:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458405#M116330</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-04-29T00:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458418#M116340</link>
      <description>Can you elaborate this %include code in my scenario</description>
      <pubDate>Sun, 29 Apr 2018 03:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458418#M116340</guid>
      <dc:creator>suresh123</dc:creator>
      <dc:date>2018-04-29T03:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458420#M116341</link>
      <description>So what iam looking is, I dont want to enter the dates manually through %pull(20170101,20170501). Its need to pick from %let macro</description>
      <pubDate>Sun, 29 Apr 2018 04:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458420#M116341</guid>
      <dc:creator>suresh123</dc:creator>
      <dc:date>2018-04-29T04:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458437#M116349</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/207177"&gt;@suresh123&lt;/a&gt; wrote:&lt;BR /&gt;So what iam looking is, I dont want to enter the dates manually through %pull(20170101,20170501). Its need to pick from %let macro&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you just talking about doing something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let begin=20170101;
%let end =20170501;
%pull(&amp;amp;begin,&amp;amp;end)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Apr 2018 14:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/458437#M116349</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-29T14:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Loop between two macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/459542#M116734</link>
      <description>What if macros are given quotes&lt;BR /&gt;&lt;BR /&gt;%let begin=‘20170101’;&lt;BR /&gt;%let end =‘20170501’;&lt;BR /&gt;&lt;BR /&gt;How does loop works ?</description>
      <pubDate>Thu, 03 May 2018 05:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-between-two-macro-variables/m-p/459542#M116734</guid>
      <dc:creator>suresh123</dc:creator>
      <dc:date>2018-05-03T05:57:09Z</dc:date>
    </item>
  </channel>
</rss>

