Thursday, December 21, 2006

Aggregate analysis in SAS

If there are aggregate data rather than individual data, analysis in SAS is less intuitive compared to STATA.

/* the aim of this analysis is to assess if the proportion of infection is changing across different years */

data xtrct;
input yr inf mech upgr other;/*infection has number of infection patients */

cards;
2000 12 7 0 40
2001 10 7 1 52
2002 34 13 4 24
2003 30 27 6 21
;

/* We need to convert this wide data set into long dataset*/
data trite;
set xtrct;
ninf=mech+upgr+other; /*total number of non infection patients */
ARRAY a(1:2) inf ninf;
DO t = 1 to 2 ;
num= a(t) ;
indicinf=t; /*indicator if num represents infections or non infections */
OUTPUT ;
END ;

proc print;
run;

/* The data table should be as follows. Note num corresponds to number of cases with infection and without infection.*/

Obs yr inf mech upgr other ninf inf infi num
1 2000 12 7 0 40 47 12 1 12
2 2000 12 7 0 40 47 12 2 47
3 2001 10 7 1 52 60 10 1 10
4 2001 10 7 1 52 60 10 2 60
5 2002 34 13 4 24 41 34 1 34
6 2002 34 13 4 24 41 34 2 41
7 2003 30 27 6 21 54 30 1 30
8 2003 30 27 6 21 54 30 2 54

/* To assess the proportion of patients with infections is same over the 3 year period */

proc freq order=data;
title3 '(Two one-way tables followed by a 2x2 table)';
table yr*indicinf / chisq;
weight num;
run;

******************************************************************************
The output is here.

No comments: