Working in Batch and Creating Titles

(Author: Roland Rashleigh-Berry                                                                              Date: 09 Apr 2007)

Introduction

This document advises on how to work with Spectre (Clinical) which is a "back end" batch system.

Use the programs directory for development

Before anything else, if you are using Spectre then all your programs using SAS® software must be developed in the programs directory for a study. Do not develop programs in your home area. Whether you develop code interactively or in batch, this rule must be strictly observed. And now for  the rest....

I guess most people develop their programs using SAS software interactively these days. Some, like me, have always done their development work in batch. I know habits are hard to break and changing from interactive development to batch development might take a long time, but the way Spectre is designed, it is much quicker to do all your development in batch. This is because there have been a lot of Unix shell scripts written that you will need to use and these are launched from the terminal window.

The final output run will be in batch so, for QC purposes, you should work as closely as possible to that method. In the final output run, each program will be run using the script "sasb" which will give a count of error messages, warning and messages of interest such as zero observations. You will have to check all of these. Details of the messages can be displayed using the script "sc" (short for scan logs). So even if you are editing your program using an interactive SAS session, you should run it from the terminal window using "sasb" and check the log messages using "sc". It should also be noted that in the final run, every program will be run independently using separate invocations of "sasb". This avoids any potential problem of one program affecting another and is the only sure way to know that the program that has passed its QC will work in an identical way for the final run.

Batch for the final run

It seems that any software company that creates clinical trials reporting systems assumes that the pharmaceutical companies want to see results interactively. Sometimes this is useful for when departments with no programmers want to see ad-hoc tables but when the final run is done to build datasets and produce output then all pharmaceutical companies I know of do this in batch. They need to keep complete records of who did what and when and this is difficult if a person is using an interactive system, so pure batch is preferred. Spectre is most definitely a batch-based system with full logging of who launches the final run, when it starts and when it ends and it keeps the return codes that come out of "sasb" for every program run.

Emulating an interactive SAS® session

To make working in batch easier, I have written some scripts to emulate a SAS session. Before you can use it you have to set up a Unix system environment variable named "prog" that is set to the name of the program you are working on (but without the ".sas" extension). If your program is "t_fpatdem.sas" then you would define it to the Unix variable "prog" like this:
 
prog=t_fpatdem
export prog

The "export prog" command has only to be done once per terminal window. It "promotes" the variable to being "global" so that other scripts you use can be aware that it is there (it is like declaring a SAS software macro variable as %global).

Once your program name has been assigned to "prog" and exported, then there are other scripts you can use to emulate a SAS interactive session. They call dtpad (or nedit) in either edit mode or browse mode. "pgm" will open up your ".sas" file in edit mode. "log" will open the log in browse mode. "lst" will open the .lst file in browse mode. "lis" will open up your .lis file (".lis" files are explained in another section - they are effectively .lst files with page number added). The abbreviations "pgm", "log" and "lst" are borrowed from interactive SAS sessions. If used on the command line then they will take you to those windows. So what I have done with these scripts is make interactive users of SAS software "feel at home" if they swap over to using batch.

(Note that I have introduced some scripts in the above paragraph. All scripts introduced on a page will be listed at the top of the page. If you look at the top of this page you will see these scripts listed plus some more).

Setting up titles

Before I go into how to create titles (and footnotes), I want to explain why titles are kept separate from program code. Maybe you are not used to this and have always put titles statements in with your reporting code. The reason titles are kept separate, with any reporting system, is because titles change from study to study but reporting macros should be reused, for the sake of efficiency. The main point of having a reporting system is to produce output efficiently. If you have to edit a reporting macro to change titles then this is not efficient and the macro is not reusable. If it is reusable then the macro should not be edited. It might even be "read only" in which case you would not be able to edit it. So since titles are changeable and you want reporting macros to remain stable, you put the changeable elements somewhere else. So the changeable titles are to go in a "titles" member, later to be read in by SAS software code and placed in a dataset. Notice that I highlighted "changeable titles" because not all titles change. Suppose you called a reporting macro for AEs and you set a flag that said you only wanted "serious" AEs. Then it might be better if the macro set up the term "serious AEs" in a title inside the macro. That way there is less chance of making a mistake. So you might have a changeable title with the label "Table 1.2.1" but have other non-changeable titles generated inside the macro. In this case you would only keep the "Table 1.2.1" separate because it is a changeable title. The same applies to the footnotes. If the footnotes are closely related to what the reporting macro is creating, then you would keep the footnotes in the macro code and not put them in the titles member.

So now we come to creating our changeable titles (and footnotes). Assuming you are working in batch mode, this is how to set up titles. Your titles file name will match your program name but have the extension ".titles". If you know another titles member that closely matches the program defined to "prog" then you can copy it across like this:
 
cp oldprog.titles $prog.titles

But if you want to start with a fresh set of titles (or wish to edit the current titles) then just run the command "titles" like this:
 
titles

When you do this, an editor window is opened with your titles information. A fresh set of titles is shown below. It was created for the program "t_fpatdem" and you will see that this program name was added automatically. The header contains instructions on how to fill in the details. Right at the top of the header, in the second line, it says "You must only have ONE set of titles in this file". Certainly you will not be allowed to have multiple entries for different programs. But you can have multiple entries for the same program, though your site standards may strongly discourage this. But sometimes you have no choice, despite site standards. For example, if you use "proc lifetest" then you will probably create a table from the output dataset but you will need to put the output from the procedure into a listing. You should not have a separate program - one for the table and one for the procedure output - because you have to be sure the procedure output exactly matches the information in your table. So in this case, no matter what your site standards are, you will need two entries - one for the table and one for the listing. To add an extra entry, just copy the block where you enter information and place it below. You then have to add a "label" line and give the label a value like "a" like this:
 
program: t_fpatdem
label: a

It is best to put the "label:" line under the "program:" line. Your output file will normally have the extension ".lis" (like a .lst file but with page numbers added) but if you use the label "a" then the extension will be ".lisa". The label suffixes the extension. And whereas the command "lis" (mentioned above) will open the output file with a ".lis" extension in a browser window, the command "lis a" will open the output file with a ".lisa" extension in a browser window.
 
#===========================================================================================================================================
# Template for titles.      Make a copy of this to go with your sas program and give it the file extension .titles such as t_meds.titles
#                           You must only have ONE set of titles in this file.
#
# This member was generated by the script "crtitlestmpl" for:
#
# DRUG: XXXXX_xxx
#
# STUDY: xx_xx_xx
#
# INC: xxx
#
# DATE: 03-Feb-2006
#
#===================== THE LINES BELOW THAT START WITH A # ARE A GUIDE TO TELL YOU HOW TO FILL IN THE INFORMATION =========================
#
# program: progname (put your program name here without the .sas extension. Case should match your program member name)
#
# layout: Leave blank to use study default or set it to l/p (landscape/portrait) [t] (tight lines) f (font size)
#         Here is a list of valid possible values: l8 l8.5 l9 l10 lt8 lt8.5 lt9 lt10 p8 pc8 p9 pt9 p10 pt10 p11 pt11
#         The preference is for p10 (portrait 10 point). If your report will not fit on the page then try l10 (landscape 10 point)
#         but if it still will not fit then try l9 and if it still will not fit then try l8. You should not go lower than an 8 point
#         font without asking for permission to do so.
#
# population: FAS, PPS, SEL etc. abbreviations. This must match one of the analysis set abbreviations in "protocol.txt".
#
# sascode: If you set this to anything, the sas program will be generated and any corresponding program you have will be overwritten.
#
# titles below: Put your titles BELOW this line. All titles will be CENTRED unless you start with a space in which case LEFT-ALIGNED.
# Table 1.2.3
# ANOTHER TITLE LINE
#  A LEFT-ALIGNED TITLE - THE FIRST SPACE WILL BE DROPPED WHEN IT IS LEFT-ALIGNED BUT EXTRA SPACES WILL BE SHOWN
# footnotes below: Put your footnotes BELOW this line. All footnotes will be LEFT-ALIGNED. Leading spaces are allowed.
# First footnote
# Second footnote
#   Third footnote indented two spaces
#
# endxxx: This line ends the titles entry. Do not specify anything after it.
#===========================================================================================================================================
program: t_fpatdem
layout:
population:
sascode:
#################### Columns ruler for titles and footnotes -- do not exceed the maximum column for your layout ############################
#--------1---------2---------3---------4---------5---------6---------7---------8---------9---------0---------1---------2---------3---------4
titles below:
footnotes below:
endxxx:
#--------1---------2---------3---------4---------5---------6---------7---------8---------9---------0---------1---------2---------3---------4

Below is shown details you might fill in for the program "t_fpatdem" (the header and column rulers are removed).
 
program: t_fpatdem
layout: p10
population: fas
sascode: %inc alloc m_patdem; %m_patdem
titles below:
Table 13.2.1
PATIENT DEMOGRAPHICS
footnotes below:
endxxx:

If you look at the entry above, you will see that I have chosen a portrait 10 point font size layout. The population is "fas" and this will match one of the populations set up in the file "protocol.txt" by the administrator. The first title is "Table 13.2.1" and the second title is "PATIENT DEMOGRAPHICS". The first title is definitely a changeable title and so should go in this file but "Patient Demographics", at first sight, looks like it should go in the reporting macro because it is a stable title. But sometimes you have "subjects" in a study rather than "patients" (they may be healthy volunteers) so because this word might change I have put it in the titles file and left it out of the reporting macro. There are no footnotes defined above. There will be footnotes in the report but these are closely linked to what the reporting macro is doing.

Now take a look at the "sascode:" entry above. This will be explained further in the next section.

Using sascode:

In my titles member for t_fpatdem I defined some SAS software code to the "sascode:" line as follows:
 
sascode: %inc alloc m_patdem; %m_patdem

The above is real SAS software code that will be used to create the report. Because something is defined to "sascode:", a dummy program using SAS software code will be generated with this program code in - namely "%inc alloc m_patdem; %m_patdem". Note that the dummy program generated will have the same name as your titles member but with the extension ".sas" so do not both use sascode: and have a genuine program of that name as it will get overwritten. This is a real example from a study I am working on at the moment. In an ideal world, the entry would simply be:
 
sascode: %m_patdem

...but I have to call a macro named "%alloc" to allocate libraries and since the study program library is not defined to the "sasautos" path, which contains the study specific macros I am using, then I have to include the macro "m_patdem" before I can use it. In an ideal world, this allocation of libraries and adding all the macros you need to the "sasautos" path should be done when you invoke SAS software. Using "sascode:" like this, and putting calls to reporting macros in the titles member, is the power of Spectre and how it aims at the ultimate goal of producing reports directly from the data. This is why I wrote Spectre. It is intended to be used in this way for tables, at least. You should aim to produce as many tables as you can using a short call to a reporting macro in the "sascode:" entry as shown above.

Special characters in titles and footnotes

Sometimes it is a requirement to have a percent sign "%" or an ampersand sign "&" in titles or footnotes. This can cause problems to SAS software as a percent sign can signal that a macro must be run and an ampersand sign can signal that a macro variable should be resolved. To get around this problem, these characters will be translated to something else and changed back later. But sometimes you will want to resolve some macro variables in your titles or footnotes. This might be a set of standard footnotes that you want all programmers to use. To allow you to do this, macro variable references will be resolved only if the macro variable name start with an underscore. But remember that global macro variables that both start and end with an underscore are reserved by the reporting system. You must not create them yourself. But you can create your own macro variables that only start with an underscore.

There are two global macro variables you will use in your titles or footnotes. &_poplabel_ is the population label. If the titles macro sees that defined to the titles in the titles member then it will resolve it and the client titles macro should not repeat it after the titles, if the macro works in that way. Another very common first footnote is &_longline_ which resolves to a line of underscores that is the same width as the page. It is traditional to have this as a footnote, even if it is the only one, as it gives the message to anyone reading the report that no lines of data have been accidentally missed off due to a truncated file (or the printer running out of toner/ink). The complete list of global macro variables set up is covered on the page that deals with the %titles macro, the next page to read (you can link to it here) but &_poplabel_ and &_longline_ are the only ones you will need to remember for use in titles and footnotes. Here is an example of these being used in a titles member.
 
titles below:
TABLE 13.4.5.1
PATIENT DEMOGRAPHICS - &_poplabel_
footnotes below:
&_longline_
endxxx:

Creating the titles dataset

Setting up a titles member will have no effect until you run the script "crtitlesds" which is short for (create titles dataset). When you invoke this script, SAS software will read in this file and put your titles in a "titles dataset". The script takes no arguments or parameters. You use it like this:
 
crtitlesds

When invoked it will run on all titles members owned by all programmers in that directory. It will do error checking to make sure the the table reference number is not already in use and it will check that the program name used in the titles member matches the file name of the titles member.

When you start using Spectre you will often forget to run the "crtitlesds" script after making changes. Even I forget, sometimes, and I have been using the system for two years. For example, you may need ot use more columns so you might change the layout to use a smaller font. You run your code again and nothing has changed. That is because you forgot to run "crtitlesds" to update the information in the titles dataset.

The sascode: generated program

If you define something to "sascode:" then a program will be automatically generated with that code in when you invoke the "crtitlesds" script. It will overwrite anything that is already there so you should take care you do not lose some code you want to keep. And it is no good editing the sas program generated, since it will get overwritten next time "crtitlesds" is invoked. In the case of "t_fpatdem" this is the sas code generated:
 
/*
/ Program      : t_fpatdem.sas
/ Author       : Automatically generated by the "crtitlesds" script
/ Date         :  8-Feb-2006 at 08:39:31
/ Drug         : XXXXX_xxx
/ Protocol     : xx_xx_xx
/ Increment    : xxx
/ Notes        : Do not edit this member as it will get overwritten next time
/                "crtitlesds" is run. If you wish to change the code you must
/                change it in the .titles member.
/==============================================================================*/

%inc alloc m_patdem; %m_patdem

Browsing your titles entry

If there are multiple programmers working on a study then the titles dataset will be updated every time one of the programmers invokes the "crtitlesds" script. For this they will need write access, so if anybody is browsing the dataset they will not be able to update it. For this reason I wrote the script "showtitles" that will display what is in the titles dataset in your terminal window. It reads the titles dataset in a fraction of a second and then releases it, so it does not stop other programmers from updating the titles dataset when they invoke "crtitlesds".

Here is what I get when I use it for t_fpatdem (which has been defined to the Unix variable "prog"):
 
showtitles $prog

Program: t_fpatdem
Label:
Population: FAS
Layout: P10
Sascode: %inc alloc m_patdem; %m_patdem
Titles below:
Table 13.2.1
PATIENT DEMOGRAPHICS

You might think it is reading your titles member, but it is definitely reading the titles dataset. You will see, from the above, that the "label" is a blank and it does not show footnotes as there are none in the titles dataset.

Note that if you use the command "showtitles" it will show you all the titles entries. Not just for you but for the other programmers as well.

Conclusion

You have seen how to set up titles. How you call them into a program is explained on a different page. You have been introduced to a number of scripts, all of which are listed at the top of this page. It has also been explained to you how to use the full power of Spectre by using the "sascode:" entry to produce your table with a short call to a reporting macro.
 
 

Use the "Back" button of your browser to return to the previous page.

contact the author





SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.

World Wide view of titles and program
Secure SFTP and FTPS provided by FREE GoFTP Client