SAS code

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
libname mydata "/courses/u_coursera.org1/i_1006328/c_5333" access=readonly;

DATA new; set mydata.nesarc_pds;

/*major depressive disorder ~ Sex, average daily quantity of alcohol consumed and cigarettes smoked in past 12 months, and use of sedatives, tranquilizers, cannabis, opioids, amphetamines, cocaine, heroine, hallucinogens, and inhalants*/

LABEL MAJORDEPLIFE="major depressive disorder (lifetime)"
SEX="biological sex"
S2AQ8B="alcohol consumed daily" 
S3AQ3C1="cigarettes smoked in past 12 months"
S3BQ1A1="use of sedatives"
S3BQ1A2="use of  tranquilizers"
S3BQ1A3="use of opioids"
S3BQ1A4="use of amphetamines"
S3BQ1A5="use of cannabis"
S3BQ1A6= "use of cocaine"
S3BQ1A7= "use of hallucinogens"
S3BQ1A8= "use of inhalants"
S3BQ1A9A="use of heroin";

/* DATA MUNGING */

/* for the  following variables: alcohol consumed, cigarettes smoked */
 /* change [9] to [NA] */

IF S2AQ8B=99 THEN S2AQ8B=.; /*alcohol*/
IF S3AQ3C1=99 THEN S3AQ3C1=.; /*cigarette*/

/* for the  following variables: "sex", "sedatives", "tranquilizers", "cannabis", "opioids", "amphetamines", "cocaine", "heroine", "hallucinogens", "inhalants" */
 /* change the binomial setting [1,2] --> [1,0] */
 /* change [9] to [NA] */

IF SEX=2 THEN SEX=0;

IF S3BQ1A1=2 THEN S3BQ1A1=0;
IF S3BQ1A2=2 THEN S3BQ1A2=0;
IF S3BQ1A3=2 THEN S3BQ1A3=0;
IF S3BQ1A4=2 THEN S3BQ1A4=0;
IF S3BQ1A5=2 THEN S3BQ1A5=0;
IF S3BQ1A6=2 THEN S3BQ1A6=0;
IF S3BQ1A7=2 THEN S3BQ1A7=0;
IF S3BQ1A8=2 THEN S3BQ1A8=0;
IF S3BQ1A9A=2 THEN S3BQ1A9A=0;

IF S3BQ1A1=9 THEN S3BQ1A1=.;
IF S3BQ1A2=9 THEN S3BQ1A2=.;
IF S3BQ1A3=9 THEN S3BQ1A3=.;
IF S3BQ1A4=9 THEN S3BQ1A4=.;
IF S3BQ1A5=9 THEN S3BQ1A5=.;
IF S3BQ1A6=9 THEN S3BQ1A6=.;
IF S3BQ1A7=9 THEN S3BQ1A7=.;
IF S3BQ1A8=9 THEN S3BQ1A8=.;
IF S3BQ1A9A=9 THEN S3BQ1A9A=.;

IF S3AQ3B1=9 THEN S3AQ3B1=.;
IF S3AQ3C1=99 THEN S3AQ3C1=.;

IF S2AQ8A=99 THEN S2AQ8A=.;
IF S2AQ8B=99 THEN S2AQ8B=.;

/* DATA BINNING - from QUANTITATIVE to CATEGORICAL BINS */

/*SMOKE = from FREQUENCY IN DAYS converted to NUMBER OF DAYS PER YEAR (days per year) */
IF S3AQ3B1= 1 THEN SMOKEFREQYR = 364;
ELSE IF S3AQ3B1= 2 THEN SMOKEFREQYR = 286;
ELSE IF S3AQ3B1= 3 THEN SMOKEFREQYR = 182;
ELSE IF S3AQ3B1= 4 THEN SMOKEFREQYR = 78;
ELSE IF S3AQ3B1= 5 THEN SMOKEFREQYR = 30;
ELSE IF S3AQ3B1= 6 THEN SMOKEFREQYR = 1;

/* assign NEW VARIABLE pack-years */
CIGSPERYEAR = SMOKEFREQYR * S3AQ3C1;

/* ALCOHOL = from FREQUENCY IN DAYS converted to NUMBER OF DAYS PER YEAR (days per year) */
IF S2AQ8A= 1 THEN ALCOHOLFREQYR = 364;
ELSE IF S2AQ8A= 2 THEN ALCOHOLFREQYR = 286;
ELSE IF S2AQ8A= 3 THEN ALCOHOLFREQYR = 182;
ELSE IF S2AQ8A= 4 THEN ALCOHOLFREQYR = 104;
ELSE IF S2AQ8A= 5 THEN ALCOHOLFREQYR = 52;
ELSE IF S2AQ8A= 6 THEN ALCOHOLFREQYR = 30;
ELSE IF S2AQ8A= 7 THEN ALCOHOLFREQYR = 12;
ELSE IF S2AQ8A= 8 THEN ALCOHOLFREQYR = 9;
ELSE IF S2AQ8A= 9 THEN ALCOHOLFREQYR = 4.5;
ELSE IF S2AQ8A= 10 THEN ALCOHOLFREQYR = 1.5;

/* assign NEW VARIABLE drink-years */
SWIGSPERYEAR = ALCOHOLFREQYR * S2AQ8B;

/*make bins for quantitative explanatory variables cigsperyear */
if CIGSPERYEAR LE 2002 then G4CIGS =1001.5;
else if CIGSPERYEAR LE 4550 then G4CIGS = 3276; 
else if CIGSPERYEAR LE 7644 then G4CIGS =6097; 
else if CIGSPERYEAR GT 7644 then G4CIGS =21658; 

/*make bins for quantitative explanatory variables swigsperyear */

if SWIGSPERYEAR LE 10.5 then G4SWIGS = 6;
else if SWIGSPERYEAR LE 63 then G4SWIGS = 36.75; 
else if SWIGSPERYEAR LE 360 then G4SWIGS =211.5; 
else if SWIGSPERYEAR GT 360 then G4SWIGS =35852; 

/*sort tables by row identifier*/
PROC SORT; by IDNUM;

/*PROC ANOVA; CLASS MAJORDEPLIFE;
MODEL AGE=MAJORDEPLIFE;
MEANS MAJORDEPLIFE /TUKEY;*/

/*PROC ANOVA; CLASS G4CIGS;
MODEL AGE=G4CIGS;
MEANS G4CIGS /TUKEY;*/

/*PROC ANOVA; CLASS G4SWIGS;
MODEL AGE=G4SWIGS;
MEANS G4SWIGS /DUNCAN;*/

/*print each observation with the following variables in columns */
/*PROC PRINT; VAR MAJORDEPLIFE SEX  G4CIGS G4SWIGS S3BQ1A1 S3BQ1A2 S3BQ1A3 S3BQ1A4 S3BQ1A5 S3BQ1A6 S3BQ1A7 S3BQ1A8 S3BQ1A9A*/ ;

/*check center, spread, shape*/
/*PROC UNIVARIATE; VAR  G4CIGS G4SWIGS MAJORDEPLIFE SEX S3BQ1A1 S3BQ1A2 S3BQ1A3 S3BQ1A4 S3BQ1A5 S3BQ1A6 S3BQ1A7 S3BQ1A8 S3BQ1A9A*/ ;

/*check frequency tables*/
/*PROC FREQ; TABLES MAJORDEPLIFE SEX G4CIGS G4SWIGS S2AQ8B S3AQ3C1 S3BQ1A1 S3BQ1A2 S3BQ1A3 S3BQ1A4 S3BQ1A5 S3BQ1A6 S3BQ1A7 S3BQ1A8 S3BQ1A9A*/ ;

RUN;

/*get multiple pairwise tables for chi-squared test*/

/*this is for comparing G4CIGS classes versus majordepressive disorder*/
/*Bonferonni correction is 0.05 divided by 6 equals 0.008333333 */

DATA CIGSCOMPARISON1; set NEW;
IF G4CIGS=1001.5 or G4CIGS=3276;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4CIGS /CHISQ;

RUN;

DATA CIGSCOMPARISON2; set NEW;
IF G4CIGS=1001.5 or G4CIGS=6097;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4CIGS /CHISQ;

RUN;

DATA CIGSCOMPARISON3; set NEW;
IF G4CIGS=1001.5 or G4CIGS=21658;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4CIGS /CHISQ;

RUN;

DATA CIGSCOMPARISON4; set NEW;
IF G4CIGS=3276 or G4CIGS=6097;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4CIGS /CHISQ;

RUN;

DATA CIGSCOMPARISON5; set NEW;
IF G4CIGS=3276 or G4CIGS=21658;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4CIGS /CHISQ;

RUN;

DATA CIGSCOMPARISON6; set NEW;
IF G4CIGS=6097 or G4CIGS=21658;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4CIGS /CHISQ;

RUN;

/*this is for comparing G4SWIGS classes versus majordepressive disorder*/
/*Bonferonni correction is 0.05 divided by 6 equals 0.008333333 */

DATA SWIGSCOMPARISON1; set NEW;
IF G4SWIGS=6 or G4SWIGS=36.75;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4SWIGS /CHISQ;

RUN;

DATA SWIGSCOMPARISON2; set NEW;
IF G4SWIGS=6 or G4SWIGS=211.5;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4SWIGS /CHISQ;

RUN;

DATA SWIGSCOMPARISON3; set NEW;
IF G4SWIGS=6 or G4SWIGS=35852;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4SWIGS /CHISQ;

RUN;

DATA SWIGSCOMPARISON4; set NEW;
IF G4SWIGS=36.75 or G4SWIGS=211.5;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4SWIGS /CHISQ;

RUN;

DATA SWIGSCOMPARISON5; set NEW;
IF G4SWIGS=36.75 or G4SWIGS=35852;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4SWIGS /CHISQ;

RUN;

DATA SWIGSCOMPARISON6; set NEW;
IF G4SWIGS=211.5 or G4SWIGS=35852;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*G4SWIGS /CHISQ;

RUN;

/*COMPARE SUBSTANCES versus MDD */
/*for a 2 by 2 case, we are inclined to call the chi square statistic large, if it is larger than 3.841*/
/* you may check out http://math.hws.edu/javamath/ryan/ChiSquare.html for the table of df versus alpha*/
/*p value is simply 0.05, since it's not a multiple pairwise test*/

DATA COMPARISONS; set NEW;
PROC SORT; by IDNUM;

PROC FREQ; TABLES  MAJORDEPLIFE*S3BQ1A1 /CHISQ; /*sedatives*/
PROC FREQ; TABLES  MAJORDEPLIFE*S3BQ1A2 /CHISQ; /*tranq*/
PROC FREQ; TABLES  MAJORDEPLIFE*S3BQ1A3 /CHISQ; /*opioids*/
PROC FREQ; TABLES  MAJORDEPLIFE*S3BQ1A4 /CHISQ; /*amphet*/
PROC FREQ; TABLES  MAJORDEPLIFE*S3BQ1A5 /CHISQ; /*cannabis*/
PROC FREQ; TABLES  MAJORDEPLIFE*S3BQ1A6 /CHISQ; /*cocaine*/
PROC FREQ; TABLES  MAJORDEPLIFE*S3BQ1A7 /CHISQ; /*hallucinogens*/
PROC FREQ; TABLES  MAJORDEPLIFE*S3BQ1A8 /CHISQ; /*inhalants*/
PROC FREQ; TABLES  MAJORDEPLIFE*S3BQ1A9A /CHISQ; /*heroin*/

RUN;