/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*********** Import the popoluation data, using the "Statistics Finland's PX-Web databases-Population". ************/
/**** The data file is placed at 'e:\Population according to age (1-year) and gender by area 1980 - 2009.txt'.** ***/
/*******************************************************************************************************************/
/********* Label: age=age group tpop=genders total population mpop=male population fpop=female population ********/
/***************** Note: the "c_" prefix indicate the character formate of the varible ****************************/
/*******************************************************************************************************************/
/*******************************************************************************************************************/
data chapter2;
infile 'e:\Population according to age (1-year) and gender by area 1980 - 2009.txt'
missover truncover delimiter='09'x linesize= 1000;
input (c_age c_tpop1980-c_tpop2009 c_mpop1980-c_mpop2009 c_fpop1980-c_fpop2009)($);
array c[*] c_age c_tpop1980-c_tpop2009 c_mpop1980-c_mpop2009 c_fpop1980-c_fpop2009;
array n[*] age tpop1980-tpop2009 mpop1980-mpop2009 fpop1980-fpop2009;
do i=1 to 91;
n[i]=input(compress(c[i]),best.);
end;
run;
proc sort data=chapter2 out=chapter2;
by age;
run;
/*******************************************************************************************************************/
/*******************************************************************************************************************/
/***************************************** Calculate the sex ratio. ************************************************/
/********* Label: sex_ratio=sex ratio age_interval=age interval cml=cumulative ********/
/*******************************************************************************************************************/
/*******************************************************************************************************************/
%MACRO CHAPTER2(year);
title 'Calculate the sex ratio';
data chapter2;
set chapter2 end=end_of_dataset;
sex_ratio&year.=mpop&year./fpop&year.;
if sex_ratio&year.<=1 then exist_sexratio&year. +1;
if exist_sexratio&year.=1 then sr_convers_age&year.=age;
sr_convers_age2&year.+sr_convers_age&year.;
age_interval =sum(age,-lag(age));
age_multip_tpop&year.=age*tpop&year.;
cml_age_multip_tpop&year. +age_multip_tpop&year.;
cml_tpop&year. +tpop&year.;
cml_mpop&year. +mpop&year.;
cml_fpop&year. +fpop&year.;
if age>=24 and age<=44 then do;
marriage_mpop&year.= mpop&year.;
end;
if age>=20 and age<=40 then do;
marriage_fpop&year.= fpop&year.;
end;
cml_marriage_mpop&year. +marriage_mpop&year.;
cml_marriage_fpop&year. +marriage_fpop&year.;
if end_of_dataset then do;
mean_age&year.=cml_age_multip_tpop&year./cml_tpop&year. + age_interval/2;
sex_ratio_population&year.=cml_mpop&year./cml_fpop&year.;
sex_ratio_marriage&year.=cml_marriage_mpop&year./cml_marriage_fpop&year.;
end;
run;
ods listing close;
ods output Summary=sumpop&year.;
proc means data=chapter2 sum;
var tpop&year.;
run;
ods listing;
data chapter2;
set chapter2 end=end_of_dataset;
if _n_=1 then set sumpop&year.;
cml_tpop_percentage&year.=cml_tpop&year./tpop&year._Sum;
if cml_tpop_percentage&year. >0.5 then do;
calc_median_age&year.= age +(((tpop&year._Sum/2)-cml_tpop&year.)/tpop&year._Sum)*age_interval;
exist_median_age&year. +1;
if exist_median_age&year. ^=1 then calc_median_age&year.=.;
end;
median_age&year. +Calc_median_age&year.;
select;
when(age<15) age_structure&year.=1;
when(age>=15 and age<65) age_structure&year.=2;
when(age>=65) age_structure&year.=3;
end;
select (age_structure&year.);
when(1) young_tpop&year.=tpop&year.;
when(2) laborforce_tpop&year.=tpop&year.;
when(3) old_tpop&year.=tpop&year.;
end;
cml_young_tpop&year. + young_tpop&year.;
cml_laborforce_tpop&year. +laborforce_tpop&year.;
cml_old_tpop&year. +old_tpop&year.;
if age in (25,30,35,40,45,50,55,60) then Calc_whipple_index_over&year.=tpop&year.;
if age >=23 and age <=62 then Calc_whipple_index_under&year.=tpop&year.;
whipple_index_over&year. +Calc_whipple_index_over&year.;
whipple_index_under&year. +Calc_whipple_index_under&year.;
if age>=10 then do;
Y_myers_index&year.=mod(age,10)+1;
PY_myers_index&year.=tpop&year. * Y_myers_index&year.;
end;
if age>=20 then do;
Z_myers_index&year.=9-mod(age,10);
PZ_myers_index&year.=tpop&year. * Z_myers_index&year.;
end;
MBV&year.=sum(PY_myers_index&year.,PZ_myers_index&year.);
%MACRO REMAINDER;
%DO I=0 %TO 9;
if mod(age,10)=&I. then CALC_MBV&I.&year.=MBV&year.;
%END;
%MEND;
%MACRO CUMULATE;
%DO I=0 %TO 9;
MBV&I.&year. +CALC_MBV&I.&year.;
%END;
%MEND;
%REMAINDER;
%CUMULATE;
if end_of_dataset then do;
old_young_ratio&year. =cml_old_tpop&year. /cml_young_tpop&year.;
young_coefficient&year. =cml_young_tpop&year. /cml_tpop&year.;
old_coefficient&year. =cml_old_tpop&year. /cml_tpop&year.;
Dependency_Ratio&year. =(cml_young_tpop&year. + cml_old_tpop&year.)/cml_laborforce_tpop&year.;
young_Dependency_Ratio&year. =cml_young_tpop&year. / cml_laborforce_tpop&year.;
old_Dependency_Ratio&year. =cml_old_tpop&year. /cml_laborforce_tpop&year.;
old_population_density&year. =1/old_coefficient&year.;
young_Dependency_density&year.=1/young_Dependency_Ratio&year.;
old_Dependency_density&year. =1/old_Dependency_Ratio&year.;
whipple_index&year.= whipple_index_over&year.*5/ whipple_index_under&year.;
%MACRO C;
%DO I=0 %TO 9;
C&I.&year.=MBV&I.&year./sum(OF MBV0&year.-- MBV9&year.);
%END;
%MEND;
%MACRO M;
%DO I=0 %TO 9;
M&I.&year.=ABS(C&I.&year.-0.1);
%END;
%MEND;
%C;
%M;
myers_index&year.=sum(of m0&year.-- m9&year.)/2;
end;
if end_of_dataset then do;
file print;
title 'THE BASIC DISCRIPTION OF THE POPULATION';
put /// @10 'THE SUM OF THE POPULATION'
/60*'*'
// 'The Sum Population is ' cml_tpop&year.
//60*'*'
/// @10 'THE SEX STRUCTURE OF THE POPULATION'
/60*'*'
// 'The Sum Male Population is ' @40 cml_mpop&year.
// 'The Sum Female Population is ' @40 cml_fpop&year.
// 'The Sex Ratio Of The Population is ' @40 sex_ratio_population&year.
// 'The Sex Ratio Conversion Age is ' @40 sr_convers_age2&year.
/60*'_'
// 'The Sum Marriage Male Population is ' @40 cml_marriage_mpop&year.
// 'The Sum Marriage Female Population is ' @40 cml_marriage_fpop&year.
// 'The Sex Ratio Of Marriage Population is ' @40 sex_ratio_marriage&year.
/60*'_'
/60*'*'
_page_
/// @10 'THE AGE STRUCTURE OF THE POPULATION'
/60*'*'
// 'The Mean Age Of The Population is ' @40 mean_age&year.
// 'The Median Age Of The Population is ' @40 median_age&year.
/60*'_'
// 'The Young Age Population is ' @40 cml_young_tpop&year.
// 'The Labor Force Population is ' @40 cml_laborforce_tpop&year.
// 'The Old Age Population is ' @40 cml_old_tpop&year.
/60*'_'
// 'The Old/Young Ratio is ' @40 old_young_ratio&year.
// 'The Young People Coefficient is ' @40 young_coefficient&year.
// 'The Old People Coefficient is ' @40 old_coefficient&year.
// 'The Dependency Ratio is ' @40 Dependency_Ratio&year.
// 'The Young Dependency Ratio is ' @40 young_Dependency_Ratio&year.
// 'The Old Dependency Ratio is ' @40 old_Dependency_Ratio&year.
// 'The Old Population Density is ' @40 old_population_density&year.
// 'The Young Dependency Density is ' @40 young_Dependency_density&year.
// 'The Old Dependency Density is ' @40 old_Dependency_density&year.
/60*'_'
/60*'*'
_page_
/// @5'TEST AND EVALUATE THE QUALITY OF THE POPULATION DATA'
/60*'*'
// "The Whipples's Index is " @40 whipple_index&year.
// "The Myers' Index is " @40 myers_index&year.
/60*'_'
/60*'*'
;
end;
run;
|