Professional Documents
Culture Documents
PH 14
PH 14
ABSTRACT
This paper describes how to use SAS plus Visual Basic software to develop an analysis report system, using clinical
demographic data as the analysis data. The system consists of general statistical analysis processes, output reports
which include three parts: (1) Statistical Summary (a text RTF file), (2) Analysis Graphs (a HTM file with drill-down
information) and (3) Data Listings (an Excel file with the option of multiple worksheets). All process functions are
integrated and located in one working window. The system tool is simple, efficient and powerful. Moreover, because
this tool can be built into an executable file (.exe), it is user-friendly even to those who do not have SAS experience.
INTRODUCTION
As we know, SAS is a powerful tool that can perform many statistical analysis processes and generate reports
(including text or graphs). Likewise, the Visual Basic (VB) software is also a useful tool in that it builds a user-friendly
window environment, in which a user can organize, manage and operate a variety of tasks easily. To take advantage
of the benefits of each software, we can combine SAS and Visual Basic to develop a tool for a data analysis report
system. It will be very practical in processing regular analysis for data in a standard format.
This paper describes an attempt at using this system for the above purposes. We will use VB to design a working
window with the following functions:
• Access and view the specified input data.
• Submit RunSAS1.sas to do the expected statistical analyses and generate an output text report file for
selected variables; view the report file.
• Submit RunSAS2.sas to do graphic analysis and generate a graph file for selected variables; view the graph
file.
• Submit RunSAS3.sas to generate an Excel file to list all subject data by a selected sorting variable, view
those work sheets.
Clinical demographic data structures and analysis procedures are mostly very similar. To demonstrate, we will use
some simple examples to introduce the working method of this tool.
Section 5 contains: (1) list of character variable(s) to be analyzed; (2) list of numerical variable(s) to be analyzed; (3)
submit RunSAS1.sas; (4) view output results.
Section 6 contains: (1) specify the variable to be analyzed; (2) specify the grouping variable; (3) specify graph type; (4)
submit RunSAS2.sas; (5) view the graph file.
Section 7 contains: (1) specify the group variable to be sorted; (2) submit RunSAS3.sas; (3) view generated Excel data
file.
1
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
1 2
3
7
6
8
Detail in each section, such as box names, properties and functions in Visual Basic, VB and SAS code are described
in the following:
folder = File1.Path
dsn = File1.FileName
fddsn = folder + "\" + dsn
2
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
Example:
(1) Select “C:\Project1\SAS\Data” for input data folder.
(2) Select “demog.sas7bdat” for input data set name.
(3) Click the box “View Data” then the screen will appear as below
outdir = TxtOutdir.Text
charvar = TxtCharVar.Text
numvar = TxtNumVar.Text
dsn = File1.FileName
folder = File1.Path
3
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
Else
MsgBox "No Data file selected"
End If
End Sub
%macro runsas1;
libname dirname "&dir";
ods rtf file="&outdir.\RunSAS1.rtf";
Example:
(1) Select “C:\Project1\SAS\Data” for input data folder.
(2) Select “demog.sas7bdat” for input data set name.
(3) Type “C:\Test” for input data folder.
(4) Type “TREAT SEX RACE REGION” for analysis character variables
(5) Type “AGE WEIGHTKG” for analysis numerical variables
(6) Click the box “RunSAS1”. After a while, you will see this window:
4
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
(7) Click “OK”, then click the box “View Summary”. You will see “Summary of Demographic Data Analysis” as
below:
5
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
outdir = TxtOutdir.Text
gvar = TxtGvar.Text
gby = TxtGby.Text
gtype = ListGtype
dsn = File1.FileName
folder = File1.Path
Else
MsgBox "No Data file selected"
End If
End Sub
%macro mplot;
*****************************************************;
** Part 1: Load Input Data, Assign Macro Variables **;
*****************************************************;
libname dirname "&dir";
libname outdir "&outdir";
6
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
call symput('GVAL'||trim(left(_n_)),&gvar.);
call symput('TOTAL',trim(left(_n_)));
run;
*****************************************************************;
** Part 2: Create A RTF Link File for Drill Down Information **;
** (Listing N, Mean, Min, Max, Range and Std Dev. of **;
** Age, Weight and Study Days) **;
** Options: With or without group variable (&gby) **;
*****************************************************************;
%else %do;
GraphVar=&gvar;
%do i=1 %to &total;
if &gvar ="&&gval&i." then do;
rpt="href='DrillDowns.rtf#g&i'";
end;
%end;
label GraphVar="&gvarlb";
%end;
run;
quit;
ods rtf close;
*****************************************************;
** Part 3: Count frequencies for analysis variable **;
** and create graph data (testds3) **;
*****************************************************;
7
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
*************************************;
** Part 4: Create A HTM Graph File **;
*************************************;
%end;
%end;
quit;
ods HTML close;
%mend mplot;
%mplot;
8
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
"\RunSAS2.htm"
Call Shell(cmd, 1)
End Sub
Example 1:
(1) Select “C:\Project1\SAS\Data” for input data folder.
(2) Select “demog.sas7bdat” for input data set name.
(3) Type “C:\Test” for output file folder.
(4) In the frame “Graph Analysis” (see figure 5),
(a) Type “TREAT” for analysis character variables
(b) Type “SEX” for group variables
(c) Select PIE as Graph Type
(d) Click the box “RunSAS2”. After a while, you will get the message “RunSAS2 Completed”, then click “OK”.
(e) Click the box “View Graph” to see graph file RunSAS2.htm as shown in Figure 6.
Figure 7: “Drill
Down” Information
9
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
Example 2:
(1) Change the selection of Graph Type (see figure 5) from PIE in Example 1 to BAR.
(2) Click the box “RunSAS2”. After a while, you will get the message “RunSAS2 Completed”, then click “OK”.
(3) Click the box “View Graph” to see graph file RunSAS2.htm as shown in Figure 8.
(4) Move the mouse to any bar chart to get actual counts shown in a message box.
outdir = TxtOutdir.Text
byvar = LstByvar
dsn = File1.FileName
folder = File1.Path
10
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
Else
MsgBox "No Data file selected"
End If
End Sub
data testds;
set dirname.&dsn;
run;
sdata varlst;
set varlst;
ds=compress(propcase(&byvar));
call symput('N',compress(left(_N_)));
call symput('ds'||LEFT(_N_), ds);
call symput('byvar'||LEFT(_N_), &byvar);
run;
%macro setds;
%do i=1 %to &N;
data &&ds&i;
informat SUBJID TREAT &byvar REGION RACE SEX;
set testds;
if &byvar="&&byvar&i";
run;
11
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
%macro mdxls;
%do i=1 %to &n;
data WrkBk.&&ds&i;
set &&ds&i;
run;
%end;
libname WrkBk clear;
quit;
%mend mdxls;
%mdxls;
Example :
(1) Select “C:\Project1\SAS\Data” for input data folder.
(2) Select “demog.sas7bdat” for input data set name.
(3) Type “C:\Test” for output file folder.
(4) In the frame “Data Listing” (see figure 9),
(a) Select “RACE” as “Sort By Variable”
(b) Click the box “RunSAS3”. After a while, you will get the message “RunSAS3 Completed”, then click “OK”
(c) Click the box “View Listing Sheets” to see file RunSAS3.xls as shown in Figure10.
SECTION 8: EXIT
Name of the Box: Exit
Property: CommandButton
Function: To Exit working window.
VB Code:
Private Sub Exit_Click()
Unload Me
End Sub
12
NESUG 2008 Pharmaceuticals, Health Care, and Life Sciences
RESULT OF TEST
The results of the tests were positive. All functions of the boxes in the working window have successfully met our
expectations. The user can execute any changes or settings in the listed field choices without modifying any SAS or
VB code. The tool handles the communication to SAS, MS Word, MS Excel and HTML files, and works very well. Also,
since this tool can be built into an executable (.exe) file, it is very easy and simple to use.
CONCLUSION
This is a successful attempt. The tool has combined advantages from both SAS and Visual Basic. It can load powerful
statistical analysis and reporting software (SAS), and can work with the window environment to perform all task
management and operations visually.
With the strategy of the tool, we can customize (add more or change) any options and functions upon it as needed. We
could also develop similar tools for regular analysis and reports for other standard format data, such as adverse
events, disposure, patient profile, etc..
REFERENCES
[1] Lauren E. Haworth ,“Output Delivery System”, page 250-258.
[2] SUGI 30, paper 044-30, “A Microsoft Access GUI for SAS Automation”, by Rubin Nan and David Mullins.
[3] 2005 Pharmaceutical users Software Exchange Conference, paper AS11, “Using VBA and Base SAS to Get Data
from SAS to Excel Without Data Integrity Issues”, by Timothy Adlington.
[4] SUGI 27, paper 164-27, “Using Visual Basic to Customize a Set of SAS reports”, by Kevin McGowan.
[5] “Quick Tip: Building Drill-down SAS Applications”, by Kirk Paul Lafler, http://www.sconsig.com/sastips/building_drill-
down_sas_applications.pdf.
CONTACT INFORMATION
Your comments and questions are valued and encouraged. Contact the author at:
Richard Zhou
Johnson & Johnson Pharmaceutical Research and Development, L.L.C.
920 Route 202
PO Box 300
Raritan, NJ 08869
Email: rzhou@prdus.jnj.com
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.
Other brand and product names are trademarks of their respective companies.
13