# This code calculates the AUC for outcome variable

```***This code calculates the AUC for outcome variable &quot;vasbew&quot;. Time points are indicated
by &quot;tydstip&quot;. Cases are arranged by &quot;randonum&quot; -&gt; change the variables in this code to your
own outcome and time indication.
*First transform the data file from &quot;long&quot; to &quot;wide&quot;. The code asks for the data to be in the
following format:
*randonum tydstip.1 tydstip.2 etc. vasbew.1 vasbew.2 etc.
*Transformation can be done using the &quot;casetovars&quot; method.
SORT CASES BY randonum.
CASESTOVARS
/ID=randonum
/GROUPBY=VARIABLE.
*Use the following algoritm to calculate the AUC for each case.
VECTOR time = tydstip.1 to tydstip.5.
VECTOR VASBEW = vasbew.1 to vasbew.5.
COMPUTE cmax = MAX(vasbew.1 to vasbew.5).
COMPUTE tmax = \$sysmis.
COMPUTE lagVASBEW = \$sysmis.
COMPUTE lagtime = \$sysmis.
COMPUTE auc = 0.
LOOP #k = 1 to 5.
DO IF (NOT(MISSING(VASBEW(#k)))).
IF (NOT(MISSING(lagVASBEW)))
auc = auc + (time(#k) - lagtime)*(lagVASBEW + VASBEW(#k))/2 .
IF (VASBEW(#k) = cmax and missing(tmax)) tmax = time(#k) .
COMPUTE lagVASBEW = VASBEW(#k).
COMPUTE lagtime = time(#k).
END IF.
END LOOP.
EXECUTE.
* Save file with CMAX, TMAX, and AUC added, dropping the
* intermediate variables created for their calculation .
save outfile AUC.sav
/ drop = tydstip.1 to tydstip.5 lagVASBEW lagtime.
```