DATA LIST
DATA LIST LIST /recID (F5.0) country (A20) pop (F9.0) rank (F1.0) segment (F1.0).
Reading free-form data from INLINE.
Variable |
Format |
recID |
F5.0 |
country |
A20 |
pop |
F9.0 |
rank |
F1.0 |
segment |
F1.0 |
BEGIN DATA
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
STRING newCountry (A20).
* /* Expanded: !REPLACE INSTR=country REPL="Netherlands" WITH="France" OUTSTR=newCountry. */.
.
STRING
STRING #str (A255).
COMPUTE
COMPUTE #str = country.
LOOP
LOOP IF INDEX(#str,"Netherlands") GT 0.
COMPUTE
+ COMPUTE #i = INDEX(#str,"Netherlands").
COMPUTE
+ COMPUTE #l = LENGTH("Netherlands").
COMPUTE
+ COMPUTE #str = CONCAT(SUBSTR(#str, 1, #i - 1), "France", SUBSTR(#str, #i + #l)).
COMPUTE
COMPUTE newCountry = #str.
COMPUTE
COMPUTE number = /* expanded PI */ 3.14.
COMPUTE
COMPUTE everybody = 1.
AUTORECODE
AUTORECODE VARIABLES = newCountry INTO nation.
* /* Expanded: !AGGSUB SPACCA=(everybody segment nation) VARI=(pop rank). */.
.
DATASET COPY
DATASET COPY aggsub_work.
DATASET DECLARE
DATASET DECLARE agg_1.
DATASET ACTIVATE
DATASET ACTIVATE aggsub_work.
AGGREGATE
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
DATASET DECLARE agg_2.
DATASET ACTIVATE
DATASET ACTIVATE aggsub_work.
AGGREGATE
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
DATASET ACTIVATE agg_1.
ADD FILES
ADD FILES FILE=* /FILE=agg_2.
DATASET CLOSE
DATASET CLOSE agg_2.
.
MATCH FILES
MATCH FILES FILE=* /KEEP=everybody segment nation pop rank ALL.
SELECT IF
SELECT IF NOT MISSING(segment)
OR NOT MISSING(nation)
.
SORT CASES
SORT CASES BY everybody segment nation.
APPLY DICTIONARY