*** restructures data from stacked vertical to horizontal data; proc contents data = rus.ruswork1; run; proc sort data=rus.ruswork1; by id count; run; proc freq data = rus.ruswork1; tables count; run; proc transpose data=rus.ruswork1 out=Motiv_wide prefix=motiv; by id; id count; var motiv; run; proc transpose data=rus.ruswork1 out=Metacog_wide prefix=Metacog; by id; id count; var metacog; run; data mot_meta; merge Motiv_wide Metacog_wide; by id; run; *** also restructures data from stacked vertical to horizontal data; data rus_horiz; set rus.ruswork1; by id; array motiv_array[19] motiv0-motiv18; retain motiv0-motiv18; if first.id then Do I=0 to 18; motiv_array[id]=.; end; motiv_array[id]=motiv; if last.id then output; drop i count motiv; Run; proc sort data=a1; by id timen; data db_one; set a1; by id; array stage6a[6] stage6_1-stage6_6; /* stage is coded 1=pc, 2=c, 3=prep, 4=A, 5=M, 6=NB non binger */ array zprosa[6] zpros1-zpros6; array zconsa[6] zcons1-zcons6; array zdba[6] zdb1-zdb6; array ztempsma[6] ztempsm1-ztempsm6; array znpa[6] znp1-znp6; array zbehavtruea[6] zbehavtrue1-zbehavtrue6; array zprobtruea[6] zprobtrue1-zprobtrue6; retain stage6_1-stage6_6; retain zpros1-zpros6; retain zcons1-zcons6; retain zdb1-zdb6; retain ztempsm1-ztempsm6; retain znp1-znp6; retain zbehavtrue1-zbehavtrue6; retain zprobtrue1-zprobtrue6; if first.id then Do I=1 to 6; stage6a[timen] =.; zprosa[timen] =.; zconsa[timen] =.; zdba[timen] =.; ztempsma[timen] =.; znpa[timen] =.; zbehavtruea[timen] =.; zprobtruea[timen] =.; end; stage6a[timen]=stage6; zprosa[timen]=zpros; zconsa[timen]=zcons; zdba[timen]=zdb; ztempsma[timen]=ztempsm; znpa[timen]=znp; zbehavtruea[timen]=zbehavtrue; zprobtruea[timen]=zprobtrue; if last.id then output; drop i timeN stage6 zPros zCons zDB zTempsm zNP zbehavtrue zprobtrue; Run; *** restructures data from horizontal to stacked vertical; data db_many; set db_one; array pros[6] zpros1-zpros6; array cons[6] zcons1-zcons6; array timea[6] timen1-timen6; Do I=1 to 6; zpros = pros[i]; zcons = cons[i]; timen= timea[i]; output; end; Drop zpros1-zpros6 zcons1-zcons6 timen1-timen6; run;