Hi, Dave:
What you want to do can be done with the SAS Macro facility. There are a few important things to remember about the SAS Macro facility -- it really only deals with text strings and is used to generate code. The Macro facility itself does not "do" any processing. It only generates code that goes on to the compiler.
Here's a good paper that is an introduction to the features of the SAS Macro facility:
http://www2.sas.com/proceedings/sugi28/056-28.pdf
And, below is a program that reads SASHELP.PRDSALE and makes a begin date macro variable and an end date macro variable from the dates in that one file. It sounds like you may have more than 1 file involved in your process.
You may or may not be able to do everything you need with simple SQL or %LET -- but, if you find yourself thinking "Gee, I only need to have this statement execute when some condition is true." then you may be moving into the world of writing a SAS Macro program.
The SAS Macro facility is a very powerful way to generate code. My rule of thumb, however, is to understand EXACTLY what kind of code you need to generate. So you said that you want to have something like this:
output filename = CONTINUITY_SCHEDULE_MMDDYYYY_to_MMDDYYYY
And that's good, but I would urge you to think beyond just getting the file name. In other words, where would you USE this file name:
[pre]
filename wombat "CONTINUITY_SCHEDULE_MMDDYYYY_to_MMDDYYYY.txt";
or
data perm.CONTINUITY_SCHEDULE_MMDDYYYY_to_MMDDYYYY;
set file1 file2;
run;
or
ods html file="CONTINUITY_SCHEDULE_MMDDYYYY_to_MMDDYYYY.html"
style=sasweb;
[/pre]
because you must have a good understanding of how to make the above statements syntactically correct before you introduce macro variables into the mix. For example, it would be wrong to put quotes around your file name in the %LET statement because in the DATA step usage of the output file name, the use of quotes would be incorrect. So the correct substitution of macro variables for the file name string would be:
[pre]
filename wombat "&outfl..txt";
or
data perm.&outfl;
set file1 file2;
run;
or
ods html file="&outfl..html"
style=sasweb;
[/pre]
The SAS Macro documentation is very good. There are also a lot of other SUGI and SGF papers on using SAS Macro programs and macro variables to automate processes and generate code.
cynthia
[pre]
*** Get min date val and max date val and put them into;
*** macro variables.;
*** Use the format wanted for the file name when creating;
*** the macro variables.;
*** Note that SASHELP.PRDSALE has a date variable called;
*** MONTH, but it is actually a SAS date value.;
*** The span of values is from Jan 1993 to Dec 1994;
*** So, the min and max can be formatted with SAS formats;
*** to make the macro variables.;
proc sql;
select min(month) format=mmddyyN8.,
max(month) format=mmddyyN8.
into :bdate, :edate
from sashelp.prdsale;
quit;
*** Look in the SAS Log for the results of these;
*** macro %LET and %PUT statements;
%let begdate = &bdate;
%let enddate = &edate;
%put the beginning date: &bdate;
%put the ending date: &edate;
%let outfl = CONTINUITY_SCHEDULE_&bdate._to_&edate;
%put outfilename is: &outfl;
** now use the macro variables in ODS HTML and PROC PRINT;
** just to do something with the 3 macro variables created;
ods html file="&outfl..html" style=sasweb;
proc print data=sashelp.prdsale(obs=15);
title "Out file= &outfl..html";
title2 "Begin = &bdate -- End = &edate";
format month mmddyy10.;
run;
ods html close;
[/pre]