I wrote a macro to do this using titles. It may be overkill, but the issue I ran into was existing titles that were defined, avoiding duplication of the id text and the limitation on the number of title lines available. I am including my macro below. It should be relatively easy to change to use footnotes instead of titles chaning the references TYPE='T' to TYPE='F'.
/*******************************************************************/
/*Purpose: */
/*This macro puts the name of the currently executing program name */
/*to the current out put destination using a title statement */
/* Programmer: Ward Ballard Sep 2007 */
/*******************************************************************/
/* Use: */
/* Syntax %sourceid; Currently no options or parameters */
/* included in the SAS code file. The file MUST have a name */
/* (i.e. saved) at some time prior to the code execution. */
/* Needs to be executed from the Enhanced Program Editor. */
/* Best if placed in a directory included in AUTOCALL, probably the*/
/* initial data directory. */
/* Place the call AFTER any desired titles and BEFORE any proc */
/* step as this includes proc calls. */
/* Only works where TITLE is used. */
/* If the user creates a new title with a gap from the last time */
/* the macro is called, i.e. Title xxx; %SOURCEID; TITLE5 YYY. */
/* The previous call to sourceid is still a valid title and the */
/* titles for both instance will appear. */
/* I have not tested how this will work with %INCLUDE files, but */
/* I think if the macro is called within the included file that is */
/* the name reported. */
/*******************************************************************/
/*Challenges: Making sure that theren't aren't blank title lines */
/* and that there is a way of handling 10 existing title lines and */
/* that we don't get redundant source statements if executed many */
/* times. */
/* Initially attempted to use other methods of getting the number */
/* of assigned titles but the dataset functions do not work */
/* as needed with the SASHELP.VTITLE data view that has title info */
/*******************************************************************/
/* this could be modified to do FOOTNOTES instead by changing the */
/* places where TYPE='T' to TYPE='F'. Remember that Footnotes will */
/* be at bottom of listing in the output window and will tend to */
/* pad the output lines used to match pagesize. This can result in */
/* many blank lines depending upon your current pagesize setting. */
/* Each ODS output type seems to treat footnotes slightly different*/
/* You have been warned. */
/*******************************************************************/
/* If you use "Source file:" as part of your titles for some reason*/
/* replace that text with something else in the macro below (could */
/* be done as a parameter but be carefull of frequent changes) */
/*******************************************************************/
/* example use: */
/* */
/* Title1 "A summary of some variables by some others"; */
/* Title2 "Among some demographic groups"; */
/* %sourceid; (must come after the title statements & before proc) */
/* */
/* Proc Freq data=mydataset; */
/* table (demo1 demo2)*(var1*var2 var1*var3); */
/* run; */
/* */
/* Result: */
/* */
/* A summary of some variables by some others */
/* Among some demographic groups */
/* Source file: D:\Data\project\codefile.sas */
/* */
/* (Freq tables) */
/* */
/*******************************************************************/
%macro SourceId;
%local nobs tnobs ttext pos;
proc sql NOPRINT;
select max (number) into :nobs
from SASHELP.VTITLE
where type='T';
QUIT;
proc sql NOPRINT;
select TEXT into :TTEXT
from SASHELP.VTITLE
WHERE NUMBER=&nobs and type='T';
QUIT;
%let nobs=%left(&nobs);
%*Check to see if the title already starts with Source file:;
%*If so, then reuse that title line. This improves utility ;
%*by not creating duplicate titles. Note that this does not ;
%*check to see if the source is actually the same as you ;
%*want to change the title when the file changes. ;
%put Initial nobs is &nobs ttext is &ttext;
%let pos = %index(&ttext,Source file:);
%if &pos = 1 %then %do; %* previous title was only source file cite;
%let ttext = Source file: %sysget(SAS_EXECFILEPATH);
title&nobs "&ttext" ;
%end;
%Else %if &pos > 1 %then %do; %* previous title had other text with source file;
%* the following line has an extr ) at the end that is treated as text;
%* this is to maintain the appearance as title10 statment below, the start parenthese is in the substr ;
%let ttext = %substr(&ttext,1,%eval(&pos-1)) Source file: %sysget(SAS_EXECFILEPATH));
title&nobs "&ttext";
%end;
%else %do; %* The text Source file is not in the title;
%if &nobs lE 0 %then %let nobs=1;
%if &nobs < 10 %then %DO;
%LET NOBS = %EVAL(&NOBS + 1);
title&nobs "Source file: %sysget(SAS_EXECFILEPATH)" ;
%END;
%IF &NOBS = 10 %THEN %DO;
%* GET THE TEXT OF THE TENTH TITLE ELEMENT AND APPEND THE PATH TEXT;
TITLE10 "%SYSFUNC(STRIP(&TTEXT)) (Source file: %sysget(SAS_EXECFILEPATH))";
%END;
%end;
%mend;