<?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: How to create a macro variable that will take a range of date values? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737439#M229900</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361528"&gt;@Shradha1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have accepted my post as solution but as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;demonstrates it's actually not working over month boundaries.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to create a list of the tables using code as provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Apr 2021 21:12:19 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-04-27T21:12:19Z</dc:date>
    <item>
      <title>How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737179#M229784</link>
      <description>&lt;P&gt;I have datasets with their names indexed on date, say ABC_20210424,&amp;nbsp;ABC_20210425,&amp;nbsp;ABC_20210426 and so on.&lt;/P&gt;
&lt;P&gt;I will be running this code daily where, on each day, I want to extract datasets for 60 days till yesterday.&lt;/P&gt;
&lt;P&gt;So, if today is APR 27,2021, my start date will be&amp;nbsp;26FEB2021 and end date will be 26APR2021.&lt;/P&gt;
&lt;P&gt;I have initialised two macro variables for these dates:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;call symputx('SD', put(intnx('day', today(), -60, 's'), yymmddn8.));&lt;BR /&gt;call symputx('ED' , put(intnx('day', today(), -1, 's'), yymmddn8.)); &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now how do I extract all the ABC tables from 26FEB to 26APR into one table, using a macro?&lt;/P&gt;
&lt;P&gt;Can a %DO statement help here?&lt;/P&gt;
&lt;P&gt;Thanks in Advance!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 07:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737179#M229784</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-04-27T07:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737186#M229791</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;you could use pipe to return the list of files in the path and filter the file names based on your variables for start and end:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('SD', put(intnx('day', today(), -60, 's'), yymmddn8.));
call symputx('ED' , put(intnx('day', today(), -1, 's'), yymmddn8.));
run;

%put &amp;amp;=SD.;
%put &amp;amp;=ED.;

%let path=C:\Temp\;
FILENAME pipedir pipe "dir ""%superq(path)\*.sas7bdat"" /b" lrecl=32767;
%*Import sas files;
DATA ds1;
  length path filename $1000 ds $32;
  infile pipedir truncover;
  input filename $char1000.;
  path="&amp;amp;path.";
  ds=tranwrd(filename,'.sas7bdat',''); 
  *keep files in range;
  if "&amp;amp;SD."&amp;lt;=scan(ds,2,'_')&amp;lt;="&amp;amp;ED.";
RUN;
FILENAME pipedir clear;

*Set files;
DATA ds2;
   set ds1 end=last;
   by filename;
   if _N_ eq 1 then do;
      *Define library;
      call execute('libname have "'||strip(path)||'" access=readonly;');
      call execute('DATA want; SET ');
   end;
   call execute(' have.'||strip(ds));
   if last then do;
      call execute('; RUN; ');
      call execute('libname have clear;');
   end;
RUN;

*Clean up;
PROC DELETE lib=WORK data=ds1 ds2; RUN;
%symdel SD ED;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 08:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737186#M229791</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-04-27T08:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737187#M229792</link>
      <description>&lt;P&gt;Extract the names from dictionary.tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start=%sysfunc(putn(%eval(%sysfunc(today())-60),yymmddn8.));
%let end=%sysfunc(putn(%eval(%sysfunc(today())-1),yymmddn8.));

proc sql noprint;
select catx(".",libname,memname) into :dsnames separated by " "
from dictionary.tables
where libname = "MYLIB" and memname between "ABC_&amp;amp;start." and "ABC_&amp;amp;end.";
quit;

data want;
set &amp;amp;dsnames.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Apr 2021 08:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737187#M229792</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-27T08:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737198#M229799</link>
      <description>Do I need to replace the 'dictionary.tables' part in the code? or use it as it is?&lt;BR /&gt;I have just replaced 'MYLIB' with my library name.&lt;BR /&gt;What else is to be changed in this code?</description>
      <pubDate>Tue, 27 Apr 2021 09:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737198#M229799</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-04-27T09:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737200#M229801</link>
      <description>&lt;P&gt;NOTE: THIS POST CURRENTLY MARKED AS SOLUTION IS INCORRECT AS OTHERS POINTED OUT BELOW.&lt;/P&gt;
&lt;P&gt;Starting with your code the following should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('SD', put(intnx('day', today(), -60, 's'), yymmddn8.));
  call symputx('ED' , put(intnx('day', today(), -1, 's'), yymmddn8.));
  stop;
run;

data want;
  set ABC_&amp;amp;sd - ABC_&amp;amp;ED;
run;
&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Just make sure you don't have other tables with a name like ABC_&amp;lt;digit&amp;gt; under this library.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 07:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737200#M229801</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-28T07:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737212#M229806</link>
      <description>&lt;P&gt;The DICTIONARY tables in SQL are metadata tables that are created on the fly when used from the current data in your libraries. The name of the table will always be the same.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 10:41:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737212#M229806</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-27T10:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737307#M229849</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Starting with your code the following should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('SD', put(intnx('day', today(), -60, 's'), yymmddn8.));
  call symputx('ED' , put(intnx('day', today(), -1, 's'), yymmddn8.));
  stop;
run;

data want;
  set ABC_&amp;amp;sd - ABC_&amp;amp;ED;
run;
&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Just make sure you don't have other tables with a name like ABC_&amp;lt;digit&amp;gt; under this library.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Actually I think this fails with any interval that crosses a month boundary because formatted dates will not be sequential.&lt;/P&gt;
&lt;PRE&gt;data abc_20210431;
   x=1;
run;

data abc_20210501;
  x=2;
run;
data abc_20210502;
  x=3;
run;
%let sd=20210431;
%let ed=20210502;

data want;
   set abc_&amp;amp;sd. - abc_&amp;amp;ed.;
run;
&lt;/PRE&gt;
&lt;P&gt;Generates these errors:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;13   data want;
14      set abc_20210431 - abc_20210502;
ERROR: File WORK.ABC_20210432.DATA does not exist.
ERROR: File WORK.ABC_20210433.DATA does not exist.
ERROR: File WORK.ABC_20210434.DATA does not exist.
ERROR: File WORK.ABC_20210435.DATA does not exist.
ERROR: File WORK.ABC_20210436.DATA does not exist.
ERROR: File WORK.ABC_20210437.DATA does not exist.
ERROR: File WORK.ABC_20210438.DATA does not exist.
ERROR: File WORK.ABC_20210439.DATA does not exist.
ERROR: File WORK.ABC_20210440.DATA does not exist.
ERROR: File WORK.ABC_20210441.DATA does not exist.
ERROR: File WORK.ABC_20210442.DATA does not exist.
ERROR: File WORK.ABC_20210443.DATA does not exist.
ERROR: File WORK.ABC_20210444.DATA does not exist.
ERROR: File WORK.ABC_20210445.DATA does not exist.
ERROR: File WORK.ABC_20210446.DATA does not exist.
ERROR: File WORK.ABC_20210447.DATA does not exist.
ERROR: File WORK.ABC_20210448.DATA does not exist.
ERROR: File WORK.ABC_20210449.DATA does not exist.
ERROR: File WORK.ABC_20210450.DATA does not exist.
ERROR: File WORK.ABC_20210451.DATA does not exist.
ERROR: File WORK.ABC_20210452.DATA does not exist.
ERROR: File WORK.ABC_20210453.DATA does not exist.
ERROR: File WORK.ABC_20210454.DATA does not exist.
ERROR: File WORK.ABC_20210455.DATA does not exist.
ERROR: File WORK.ABC_20210456.DATA does not exist.
ERROR: File WORK.ABC_20210457.DATA does not exist.
ERROR: File WORK.ABC_20210458.DATA does not exist.
ERROR: File WORK.ABC_20210459.DATA does not exist.
ERROR: File WORK.ABC_20210460.DATA does not exist.
ERROR: File WORK.ABC_20210461.DATA does not exist.
ERROR: File WORK.ABC_20210462.DATA does not exist.
ERROR: File WORK.ABC_20210463.DATA does not exist.
ERROR: File WORK.ABC_20210464.DATA does not exist.
ERROR: File WORK.ABC_20210465.DATA does not exist.
ERROR: File WORK.ABC_20210466.DATA does not exist.
ERROR: File WORK.ABC_20210467.DATA does not exist.
ERROR: File WORK.ABC_20210468.DATA does not exist.
ERROR: File WORK.ABC_20210469.DATA does not exist.
ERROR: File WORK.ABC_20210470.DATA does not exist.
ERROR: File WORK.ABC_20210471.DATA does not exist.
ERROR: File WORK.ABC_20210472.DATA does not exist.
ERROR: File WORK.ABC_20210473.DATA does not exist.
ERROR: File WORK.ABC_20210474.DATA does not exist.
ERROR: File WORK.ABC_20210475.DATA does not exist.
ERROR: File WORK.ABC_20210476.DATA does not exist.
ERROR: File WORK.ABC_20210477.DATA does not exist.
ERROR: File WORK.ABC_20210478.DATA does not exist.
ERROR: File WORK.ABC_20210479.DATA does not exist.
ERROR: File WORK.ABC_20210480.DATA does not exist.
ERROR: File WORK.ABC_20210481.DATA does not exist.
ERROR: File WORK.ABC_20210482.DATA does not exist.
ERROR: File WORK.ABC_20210483.DATA does not exist.
ERROR: File WORK.ABC_20210484.DATA does not exist.
ERROR: File WORK.ABC_20210485.DATA does not exist.
ERROR: File WORK.ABC_20210486.DATA does not exist.
ERROR: File WORK.ABC_20210487.DATA does not exist.
ERROR: File WORK.ABC_20210488.DATA does not exist.
ERROR: File WORK.ABC_20210489.DATA does not exist.
ERROR: File WORK.ABC_20210490.DATA does not exist.
ERROR: File WORK.ABC_20210491.DATA does not exist.
ERROR: File WORK.ABC_20210492.DATA does not exist.
ERROR: File WORK.ABC_20210493.DATA does not exist.
ERROR: File WORK.ABC_20210494.DATA does not exist.
ERROR: File WORK.ABC_20210495.DATA does not exist.
ERROR: File WORK.ABC_20210496.DATA does not exist.
ERROR: File WORK.ABC_20210497.DATA does not exist.
ERROR: File WORK.ABC_20210498.DATA does not exist.
ERROR: File WORK.ABC_20210499.DATA does not exist.
ERROR: File WORK.ABC_20210500.DATA does not exist.
15   run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 16:12:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737307#M229849</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-27T16:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737439#M229900</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361528"&gt;@Shradha1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have accepted my post as solution but as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;demonstrates it's actually not working over month boundaries.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to create a list of the tables using code as provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 21:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737439#M229900</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-27T21:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737453#M229914</link>
      <description>&lt;P&gt;Another way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
&amp;nbsp; set&amp;nbsp;
&amp;nbsp; %macro loop;
&amp;nbsp;  &amp;nbsp;%local i;
&amp;nbsp;  &amp;nbsp;%do i = &amp;amp;sd %to &amp;amp;ed;
&amp;nbsp; &amp;nbsp; &amp;nbsp; %if %sysfunc(exist(ABC_&amp;amp;i)) %then ABC_&amp;amp;i;
&amp;nbsp;  &amp;nbsp;%end;
  %mend;
&amp;nbsp; %loop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 21:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737453#M229914</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-04-27T21:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737455#M229915</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;Won't this will create an error for missing days like day 99?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 21:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737455#M229915</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-04-27T21:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable that will take a range of date values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737457#M229917</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361528"&gt;@Shradha1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please change the chosen solution to a solution that works.&lt;/P&gt;
&lt;P&gt;And don't choose one before trying &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 21:50:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-that-will-take-a-range-of-date/m-p/737457#M229917</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-04-27T21:50:50Z</dc:date>
    </item>
  </channel>
</rss>

