BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am looking for a piece of code that could indentify the SAS program generating an output (eg an output generated by proc tabulate), and put the path and program name in a footnote to the output.

Mxller
2 REPLIES 2
deleted_user
Not applicable
try
1 the SYSIN option for the code invoked in batch mode,
2 environment variables SAS_ExecFileName and SAS_ExecFilePath for the name of the program opened through the "file open" dialog of SAS Enhanced Editor[pre] %let this_is= %sysget(SAS_ExecFilePath) %sysfunc(getoption(sysin));
option symbolgen ;
footnote2 "&this_is ";[/pre]
Otherwise you could make your own arrangements (like filling a macro variable like &this_prog_is).

good luck

PeterCV
ballardw
Super User
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 741 views
  • 0 likes
  • 2 in conversation