SET PRINTBACK=ON. DATA LIST LIST /recID (F5.0) country (A20) pop (F9.0) rank (F1.0) segment (F1.0). BEGIN DATA 1 Germany 81 1 1 2 Netherlands 17 4 2 3 Italy 61 3 2 4 France 66 2 1 END DATA. STRING newCountry (A20). * /* Expanded: !REPLACE INSTR=country REPL="Netherlands" WITH="France" OUTSTR=newCountry. */. . STRING #str (A255). COMPUTE #str = country. LOOP IF INDEX(#str,"Netherlands") GT 0. + COMPUTE #i = INDEX(#str,"Netherlands"). + COMPUTE #l = LENGTH("Netherlands"). + COMPUTE #str = CONCAT(SUBSTR(#str, 1, #i - 1), "France", SUBSTR(#str, #i + #l)). END LOOP. COMPUTE newCountry = #str. COMPUTE number = /* expanded PI */ 3.14. COMPUTE everybody = 1. AUTORECODE VARIABLES = newCountry INTO nation. * /* Expanded: !AGGSUB SPACCA=(everybody segment nation) VARI=(pop rank). */. . DATASET COPY aggsub_work. DATASET DECLARE agg_1. DATASET ACTIVATE aggsub_work. AGGREGATE OUTFILE=agg_1 /BREAK = everybody segment /pop rank= MEAN(pop rank) /N_pop = N(pop) /N_rank = N(rank) /Nu_pop = NU(pop) /Nu_rank = NU(rank) . DATASET DECLARE agg_2. DATASET ACTIVATE aggsub_work. AGGREGATE OUTFILE=agg_2 /BREAK = everybody nation /pop rank= MEAN(pop rank) /N_pop = N(pop) /N_rank = N(rank) /Nu_pop = NU(pop) /Nu_rank = NU(rank) . DATASET ACTIVATE agg_1. ADD FILES FILE=* /FILE=agg_2. DATASET CLOSE agg_2. . MATCH FILES FILE=* /KEEP=everybody segment nation pop rank ALL. SELECT IF NOT MISSING(segment) OR NOT MISSING(nation) . SORT CASES BY everybody segment nation. APPLY DICTIONARY FROM=aggsub_work. DATASET CLOSE aggsub_work. DATASET CLOSE *. LIST.