* Record output to a Word file; ODS RTF FILE = 'C:\Documents and Settings\Rich\Desktop\Rich\LYNAM\Jan13WorkshopOutput.rtf'; * Read in the data; PROC IMPORT DATAFILE = 'C:\Documents and Settings\Rich\Desktop\Rich\LYNAM\Jan13WorkshopData.xls' OUT = NewName DBMS = XLS REPLACE; * Supply path and name of Excel file with data, supply new name for data in SAS, change XLS to XLSX if using later version of Excel; SHEET = Sheet1; * Identify tab of Excel file on which data reside; GETNAMES = YES; RUN; * List all variables; PROC CONTENTS data=NewName; RUN; * Print all values of selected variables; PROC PRINT data=NewName; VAR ID Time Drink; Run; * Define new variables; data Newname; set Newname; negurgstratum = 0; if negurg > -0.674 then negurgstratum = 1; if negurg > 0.674 then negurgstratum = 2; * Create variable to define three negative urgency strata: 0 (low), 1 (average), 2 (high); logdrink = log(drink); * Create log-transformed version of drinking; run; * Exploratory data analysis; * Plot drinking against negative urgency (freshman year); symbol1 color=black value=dot i=none ; * Define color and shape of plotting symbol; axis1 label=(height=1.5 'Negative Urgency') value=(height=1.5) order=(-3 to 3 by 1); * Define text for horizontal axis; axis2 label=(angle=90 height=1.5 'Average # of Drinks') value=(height=1.5) order=(0 to 22 by 1); * Define text for vertical axis; proc gplot data=NewName; where Time=0; * Restrict attention to freshman year; title1 'Drinking vs Negative Urgency (freshman year)'; * Include title; plot Drink*NegUrg / haxis=axis1 vaxis=axis2; run; * Plot drinking against negative urgency (sophomore year); symbol1 color=black value=dot i=none ; * Define color and shape of plotting symbol; axis1 label=(height=1.5 'Negative Urgency') value=(height=1.5) order=(-3 to 3 by 1); * Define text for horizontal axis; axis2 label=(angle=90 height=1.5 'Average # of Drinks') value=(height=1.5) order=(0 to 22 by 1); * Define text for vertical axis; proc gplot data=NewName; where Time=1; * Restrict attention to sophomore year; title1 'Drinking vs Negative Urgency (sophomore year)'; * Include title; plot Drink*NegUrg / haxis=axis1 vaxis=axis2; run; * Plot drinking against negative urgency (junior year); symbol1 color=black value=dot i=none ; * Define color and shape of plotting symbol; axis1 label=(height=1.5 'Negative Urgency') value=(height=1.5) order=(-3 to 3 by 1); * Define text for horizontal axis; axis2 label=(angle=90 height=1.5 'Average # of Drinks') value=(height=1.5) order=(0 to 22 by 1); * Define text for vertical axis; proc gplot data=NewName; where Time=2; * Restrict attention to junior year; title1 'Drinking vs Negative Urgency (junior year)'; * Include title; plot Drink*NegUrg / haxis=axis1 vaxis=axis2; run; title1 ' '; * Avoid title appearing with subsequent output; * Calculate means and standard errors for drinking by time and negative urgency stratum; proc means data=NewName mean stderr; * request mean and standard error; by time; * calculated separately at each time point; where negurgstratum=0; * for people low on negative urgency; var Drink; run; proc means data=NewName mean stderr; * request mean and standard error; by time; * calculated separately at each time point; where negurgstratum=1; * for people average on negative urgency; var Drink; run; proc means data=NewName mean stderr; * request mean and standard error; by time; * calculated separately at each time point; where negurgstratum=2; * for people high on negative urgency; var Drink; run; * Create auxiliary data set containing means and standard errors for drinking by time and negative urgency stratum; data summary; input time meanlow stderrlow meanavg stderravg meanhigh stderrhigh; datalines; 0 2.81 0.25 3.30 0.17 3.64 0.28 1 2.57 0.27 3.58 0.22 5.01 0.45 2 2.80 0.38 4.06 0.31 7.06 0.74 ; data summary1; set summary; low = meanlow - stderrlow; avg = meanavg - stderravg; high = meanhigh - stderrhigh; run; data summary2; set summary; low = meanlow ; avg = meanavg ; high = meanhigh ; run; data summary3; set summary; low = meanlow + stderrlow; avg = meanavg + stderravg; high = meanhigh + stderrhigh; run; data summarycombined; set summary1 summary2 summary3; keep time low avg high; run; * Create plot of means and standard errors for drinking by time and negative urgency stratum; title1 'Means and standard errors of drinking by negative urgency and year'; * title for plot; symbol1 i=hiloctj width=1.5 line=1 c=black value=none; * set line type, color, and plotting symbol for those low on negative urgency; symbol2 i=hiloctj width=1.5 line=2 c=blue value=none; * set line type, color, and plotting symbol for those average on negative urgency; symbol3 i=hiloctj width=1.5 line=3 c=red value=none; * set line type, color, and plotting symbol for those high on negative urgency; axis1 label=(h=1.5 'Year') value=(h=1.5 t=1 'Freshman' t=2 'Sophomore' t=3 'Junior') offset=(8,8) minor=none order=(0 to 2 by 1); * define text for horizontal axis; axis2 label=(h=1.5 angle=90 'Average # of Drinks') order=(0 to 8 by 1) value=(h=1.5); * define text for vertical axis; legend1 label=(h=1.5 'Negative urgency strata:') value=(h=1.5 'Low' 'Average' 'High') position=(top left inside) mode=protect; * define legend; proc gplot data=summarycombined; plot low*time avg*time high*time / overlay haxis=axis1 vaxis=axis2 legend=legend1; run; title1 ' '; * Avoid title appearing with subsequent output; * Fit linear mixed model with negative urgency as a categorical variable; proc mixed data=newname covtest; class id negurgstratum; * Identify categorical variables; model logdrink = negurgstratum time*negurgstratum / noint solution; * Identify response and predictors, specify no intercept and request parameter estimates; estimate 'High vs low freshman' negurgstratum -1 0 1 time*negurgstratum 0 0 0 ; estimate 'High vs low sophomore' negurgstratum -1 0 1 time*negurgstratum -1 0 1; estimate 'High vs low junior' negurgstratum -1 0 1 time*negurgstratum -2 0 2; run; * Add random effects for subjects' personal intercepts and slopes; proc mixed data=newname covtest; class id negurgstratum; * Identify categorical variables; model logdrink = negurgstratum time*negurgstratum / noint solution; * Identify response and predictors, specify no intercept and request parameter estimates; estimate 'High vs low freshman' negurgstratum -1 0 1 time*negurgstratum 0 0 0 ; estimate 'High vs low sophomore' negurgstratum -1 0 1 time*negurgstratum -1 0 1; estimate 'High vs low junior' negurgstratum -1 0 1 time*negurgstratum -2 0 2; random intercept time / subject=id type=un; * include random effects for subjects' personal intercepts and slopes; run; * Fit linear mixed model with negative urgency as a continuous variable; proc mixed data=newname covtest; class id ; * Identify categorical variables; model logdrink = negurg time time*negurg / solution; * Identify response and predictors, request parameter estimates; estimate 'High vs low freshman' negurg 2 time*negurg 0 ; estimate 'High vs low sophomore' negurg 2 time*negurg 2 ; estimate 'High vs low junior' negurg 2 time*negurg 4 ; random intercept time / subject=id type=un; * include random effects for subjects' personal intercepts and slopes; run; * Cease recording output to a Word file; ODS RTF CLOSE; RUN;