*(Q)In my data set I have 4 categories of 5 questions each I would like to calculate the mode for each category for each subject, i.e., compute modecat1, modecat2, modecat3 and modeca4 for each subject. *(A) Posted by rlevesque@videotron.ca to SPSSX-L on 2001/08/28 Note that when the distribution is multi-modal, the syntax selects the mode having the highest value. * This assumes you need the mode in the data editor. If it is sufficient to have the mode in the Output window, use FREQ with the /STATISTICS=mode subcommand. INPUT PROGRAM. SET SEED=987651423. VECTOR q(20F8.0). LOOP id=1 TO 25. + LEAVE id. + LOOP #=1 TO 20. + COMPUTE q(#)=TRUNC(UNIFORM(5)+1). + END LOOP. + END CASE. END LOOP. END FILE. END INPUT PROGRAM. EXECUTE. **** Start job. VECTOR resp=q1 TO q20. LOOP qnb=1 TO 20. COMPUTE resp=resp(qnb). COMPUTE cat=1+TRUNC(qnb/5.1). XSAVE OUTFILE='c:\\temp\\temp.sav' /KEEP=id cat qnb resp. END LOOP. EXECUTE. GET FILE='c:\\temp\\temp.sav'. * aggregate cases by response values within id and category. AGGREGATE /OUTFILE=* /BREAK=id cat resp /nbresp = N(qnb). * identify then keep the line with the largest number of cases. SORT CASES BY id cat nbresp. ADD FILES FILE=* /BY=id cat /LAST=last. SELECT IF last=1. VARIABLE LABELS nbresp 'Number of response' resp 'Response'. EXECUTE.