Introduction
Main Program
Macros Used
Output
Return to Homepage
|
Example of SAS Code
Introduction
This page gives an example of SAS code that is written by myself
for use by clients. Although the main program generates dummy data
for production of the report, the code could quite easily be adapted
use on any existing data.
While the main program and macros have been run to generate output
no responsibility will be taken by the
author or agents for use of this code and any loss and/or
damage that may result. Also it must be asked that
the code herein is for REVIEW
purposes only and may NOT be copied or used in any other way
without prior consent from the author and to do so is ILLEGAL.
Main Program
Program Name: BaseDemo.SAS
/*-----------------------------------------------------------------------------*
Program Name: BaseDemo.SAS
Purpose: Baseline Demography Statistics
Input Datasets: Dummy Data - Card File (this is included in this file to make
the program self-contained)
Output Files: BaseDemo.txt
Macros Used: STDSTAT, TITLFOOT, PAGNOOF (these are included in this file
to make the program self-contained)
Notes: This file and the files it accesses are for review
purposes only and may NOT be copied or used in any other way
without prior consent from the author. If ILLEGAL use is
made of this code, no responsibility will be taken by the
author or agents for use of this code and any loss and/or
damage that may result.
History: Original, David Franklin, 04-Mar-2003
(c)MMIII David Franklin
*-----------------------------------------------------------------------------*/
*------------------------------------------------------------------------------*;
* Set runtime options.
*------------------------------------------------------------------------------*;
options ps=54 ls=80 missing=' ' nodate nonumber sasautos=("c:\"); run;
*------------------------------------------------------------------------------*;
* Create required formats necessary for the table
*------------------------------------------------------------------------------*;
proc format;
value sectno
1=' '
2='Gender'
3='Age (years) (1)'
4='Height (cm) (2)'
5='Weight (kg) (3)';
value gender
1=' Male'
2=' Female';
value stat
1=' n'
2=' Mean'
3=' Std. Dev.'
4=' Median'
5=' Minimum'
6=' Maximum';
run;
*------------------------------------------------------------------------------*;
* Data for Table
*------------------------------------------------------------------------------*;
data demog;
infile cards;
input patid $1-3 gender birthdt date9. height weight firstdt date9. trtgrp;
attrib age length=8 label='Age (years)';
age=floor((firstdt-birthdt)/365.25); ** From Analysis Plan;
cards;
001 1 14OCT1965 165 85 15APR2002 1
002 2 27APR1975 170 70 16APR2002 2
003 2 01APR1972 140 65 17APR2002 0
004 1 17DEC1985 180 90 18APR2002 2
005 2 05JUL1968 160 75 19APR2002 1
;
run;
proc datasets library=work nodetails nolist;
modify demog;
format birthdt date9.
firstdt date9.;
label patid='Patient ID'
gender='Gender'
birthdt='Date of Birth'
height='Height (cm) at Screening'
weight='Weight (kg) at Baseline'
firstdt='Date of First Treatment'
trtgrp='Treatment Group';
quit;
run;
*------------------------------------------------------------------------------*;
* Create and All Patients Treatment Group
*------------------------------------------------------------------------------*;
data demog1;
set demog;
output;
if trtgrp in(1,2) then do;
trtgrp=9;
output;
end;
run;
*------------------------------------------------------------------------------*;
* Do statistical calculations
*------------------------------------------------------------------------------*;
** Get total patient population;
data _null_;
if 0 then set demog nobs=npats;
call symput('npats',put(npats,1.));
stop;
run;
** Frequency Calculations for Patient Number, Gender;
proc freq data=demog1;
tables trtgrp /out=patk0 noprint;
tables trtgrp*gender /out=gender0 noprint;
run;
** Statistical Calculations for Age, Height and Weight;
%stdstat(demog1,age,age0);
%stdstat(demog1,height,height0);
%stdstat(demog1,weight,weight0);
** Append the results into one dataset;
data all0;
retain npats &npats;
set patk0 (in=a)
gender0 (in=b)
age0 (in=c)
height0 (in=d)
weight0 (in=e);
keep sectno trtgrp statcode statname statrslt;
sectno=(a*1)+(b*2)+(c*3)+(d*4)+(e*5);
if a then do;
statcode=0;
statname='Number of Patients';
statrslt=put(count,3.)||' ('||put(count*100/npats,3.)||')';
end;
if b then do;
statcode=gender;
statname=put(gender,gender.);
statrslt=put(count,3.)||' ('||put(count*100/npats,3.)||')';
end;
run;
** Transpose results for report;
proc sort data=all0;
by sectno statcode statname;
run;
proc transpose data=all0 out=all1 prefix=V;
by sectno statcode statname;
id trtgrp;
var statrslt;
run;
*------------------------------------------------------------------------------*;
* Generate Report
*------------------------------------------------------------------------------*;
** Titles and Footnotes;
%titlfoot(title1,%str(David Franklin, Consultant),,XXXX);
%titlfoot(title2,%str(Study: Jelly Bean Treatment Placebo,A and B));
%titlfoot(title4,,Table 1);
%titlfoot(title5,,Baseline Demographics);
%titlfoot(footnote1);
%titlfoot(footnote2,(1) Age = floor((Date of first treatment - Date of Birth)/365.25));
%titlfoot(footnote3,(2) Height is taken at Screening.);
%titlfoot(footnote4,(3) Weight is taken at Baseline.);
%titlfoot(footnote6,BaseDemo.sas,,&sysdate:&systime);
** Generate Report;
proc printto print="c:\BaseDemo.txt" new; run;
proc report data=all1 nowindows headline split='|';
columns sectno statcode statname v0 ('Active Treatment|---' (v1 v2 v9));
define sectno /group noprint;
define statcode /group noprint;
define statname /group ' ';
define v0 /display 'Placebo' width=10;
define v1 /display ' A' width=10;
define v2 /display ' B' width=10;
define v9 /display ' Total' width=10;
compute before sectno;
line ' ';
line @8 sectno sectno.;
endcomp;
quit;
run;
proc printto; run;
** Add Page Numbering;
%pagnoof(c:\BaseDemo.txt);
run;
/*End of File*/
Macros Used
The macros PagNoOf, StdStat and TitlFoot that are used in the program
have been removed to protect
copyrighted code. If you are interested in seeing the macros then please
contact me directly.
Output
David Franklin, Consultant Page 1 of 1
Study: Jelly Bean Treatment Placebo,A and B
Table 1
Baseline Demographics
Active Treatment
----------------------------------
Placebo A B Total
------------------------------------------------------------------
Number of Patients 1 ( 20) 2 ( 40) 2 ( 40) 4 ( 80)
Gender
Male 1 ( 20) 1 ( 20) 2 ( 40)
Female 1 ( 20) 1 ( 20) 1 ( 20) 2 ( 40)
Age (years) (1)
n 1 2 2 4
Mean 30.0 34.5 21.0 27.8
Std. Dev. 2.12 7.07 8.88
Median 30.0 34.5 21.0 29.5
Minimum 30 33 16 16
Maximum 30 36 26 36
Height (cm) (2)
n 1 2 2 4
Mean 140.0 162.5 175.0 168.8
Std. Dev. 3.54 7.07 8.54
Median 140.0 162.5 175.0 167.5
Minimum 140 160 170 160
Maximum 140 165 180 180
Weight (kg) (3)
n 1 2 2 4
Mean 65.0 80.0 80.0 80.0
Std. Dev. 7.07 14.14 9.13
Median 65.0 80.0 80.0 80.0
Minimum 65 75 70 70
Maximum 65 85 90 90
--------------------------------------------------------------------------------
(1) Age = floor((Date of first treatment - Date of Birth)/365.25)
(2) Height is taken at Screening.
(3) Weight is taken at Baseline.
BaseDemo.sas 04MAR03:19:18
|