楼主: xuwei2007
5169 9

SAS做寿命表 [推广有奖]

  • 0关注
  • 0粉丝

博士生

18%

还不是VIP/贵宾

-

威望
0
论坛币
50 个
通用积分
3.6000
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
8251 点
帖子
139
精华
0
在线时间
345 小时
注册时间
2008-8-15
最后登录
2024-4-3

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
求SAS作寿命表的相关程序及资料!!  谢谢!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:SAS 寿命

沙发
weihancool 发表于 2009-12-11 13:00:57 |只看作者 |坛友微信交流群
直接去看lifetest那个就行吧~~到处都有~

使用道具

藤椅
zhuosn 发表于 2011-9-9 14:24:36 |只看作者 |坛友微信交流群
http://smjsq.sinaapp.com/     寿命计算器

使用道具

板凳
zhuosn 发表于 2011-9-9 14:29:10 |只看作者 |坛友微信交流群
http://www.redlib.cn/html/130/2000/13664040.htm   用SAS程序编制简略寿命表及去死因寿命表

使用道具

报纸
davinci37 发表于 2012-8-7 12:16:25 |只看作者 |坛友微信交流群
当年我自己编的……供参考……

/**********************************************************************************************************************/
/**********************************************************************************************************************/
/***********************************   IMPORT THE DEATH DATA AND POPUALTION DATA   ************************************/
/**************************  Label: DTH=death   T=Total   M=Male   F=Female  C_=charactar  ****************************/
/**********************************************************************************************************************/
/**********************************************************************************************************************/
data  chapter5_dth;
        infile 'E:\Deaths by age and gender 1980 - 2009.txt'
        delimiter='09'x truncover missover linesize=1000;
        input (c_age c_tdth1980-c_tdth2009 c_mdth1980-c_mdth2009 c_fdth1980-c_fdth2009)($);
        array c[*]         c_age c_tdth1980-c_tdth2009 c_mdth1980-c_mdth2009 c_fdth1980-c_fdth2009;
        array n[*]  age tdth1980-tdth2009 mdth1980-mdth2009 fdth1980-fdth2009;
        do i=1 to 91;
                n[i]=input(compress(c[i]),best.);
        end;
run;
data chapter5_pop;
        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;
/***********************************************************************************************************************/
/******************************    MERGE THE DEATH DATA AND POPUALTION DATA    *****************************************/
/***********************************************************************************************************************/
data chapter5;
        merge chapter5_dth chapter5_pop;
        by age;
run;
/***********************************************************************************************************************/
/***********************************************************************************************************************/
/**************************************    CALCULATE THE Faller LIFE TABLE    ******************************************/
/********************************    Label &g.=total/male/female &year.=1980-2009   ************************************/
/***********************************************************************************************************************/
/***********************************************************************************************************************/
option mprint symbolgen;

%MACRO LIFETABLE_FALLER(g,year);       
data chapter5;
        set chapter5  end=end;               
                &g.m&year.= &g.dth&year./ &g.pop&year.;
/******************  CALCULATE DEATH PROBABILTY  ***************************/
                &g.q&year.= (2*&g.m&year.)/(2+&g.m&year.); /*-USING INDEX METHOD-q_&g.=1-exp(- asmr_&g.);*/       
                if end then &g.q&year.=1;
/******************  CALCULATE LIVE POPULATION   ***************************/
                if age=0 then &g.L&year.=100000;
                else &g.L&year.= &g.L2&year.;
/******************  CALCULATE DEATH POPULATION  ***************************/
                &g.D&year.= &g.L&year.* &g.q&year.;
                &g.L2&year.=&g.L&year.- &g.D&year.;
                retain &g.L2&year.;
/******************  CALCULATE LIVE PEOPLE-YEAR  ***************************/
                if age=0                                 then &g.LY&year.=0.25 * &g.L&year.+0.75*&g.L2&year.;
                if age>0 and age<100         then &g.LY&year.=0.5* (&g.L&year.+&g.L2&year.);
                if age=100                                 then &g.LY&year.=0.5* &g.L&year.;
run;
/*********  CALCULATE TOTLE LIVE PEOPLE-YEAR  AND LIFE EXPECTANCY  *********/
        proc sort data=chapter5;
                by decending age  ;
        run;
        data chapter5;
                set chapter5;
                &g.T&year. + &g.LY&year.;
                &g.e&year. = &g.T&year./&g.L&year.;
        run;
        proc sort data=chapter5;
                by age;
        run;
%MEND  LIFETABLE_FALLER;
/***********************************************************************************************************************/
/***********************************************************************************************************************/
/****************************************   CALCULATE THE COALE LIFE TABLE  ********************************************/
/********************************    Label &g.=total/male/female &year.=1980-2009   ************************************/
/***********************************************************************************************************************/
/***********************************************************************************************************************/
%MACRO LIFETABLE_COALE(g,year);       
data chapter5;
        set chapter5  end=end;       
                &g.m&year.=&g.dth&year./&g.pop&year.;
/******************  IMPORT THE LIFE COEFFICIENCY  ***************************/
                select;               
                        when(age=0)                                  a=0.3;
                        when(age>=1  and age<=4)          a=0.375;
                        when(age>=5  and age<=9)          a=0.45;
                        when(age>=10 and age<=74)          a=0.52;
                        when(age>=75 and age<=79)          a=0.50;
                        when(age>=80 and age<=84)          a=0.48;
                        when(age>=85 and age<=89)          a=0.44;
                        when(age>=90)                                 a=0.42;
                        otherwise;
                end;       
/******************  CALCULATE DEATH PROBABILTY  ***************************/
                &g.q&year.=&g.m&year./(1+(1-a)*&g.m&year.);
                if end then &g.q&year.=1;
/******************  CALCULATE LIVE POPULATION   ***************************/
                if age=0 then &g.L&year.=100000;
                else &g.L&year.=&g.L2&year.;
/******************  CALCULATE DEATH POPULATION  ***************************/
                &g.D&year.=&g.L&year.*&g.q&year.;
                &g.L2&year.=&g.L&year.-&g.D&year.;
                retain &g.L2&year.;
/******************  CALCULATE LIVE PEOPLE-YEAR  ***************************/
                &g.LY&year.=a*&g.L&year.+(1-a)*&g.L2&year.;
                run;
/*********  CALCULATE TOTLE LIVE PEOPLE-YEAR  AND LIFE EXPECTANCY  *********/
        proc sort data=chapter5;
                by decending age  ;
        run;
        data chapter5;
                set chapter5;
                &g.T&year. + &g.LY&year.;
                &g.e&year.=&g.t&year./&g.L&year.;
        run;
        proc sort data=chapter5;
                by age;
        run;
%MEND LIFETABLE_COALE;
%MACRO PLOT(year);       
proc template;
        define statgraph lt;
                begingraph/designwidth=1280 designheight=960;
                        layout lattice / columns=3 rows=2 rowgutter=30 columngutter=30;
                                layout overlay/yaxisopts=(label='age specific mortality rate');
                                        seriesplot x=age y=tm&year./ lineattrs=(color=black);
                                        seriesplot x=age y=mm&year./ lineattrs=(color=blue);
                                        seriesplot x=age y=fm&year./ lineattrs=(color=red);
                                endlayout;
                                layout overlay/yaxisopts=(label='death probabilty');
                                        seriesplot x=age y=tq&year./ lineattrs=(color=black);
                                        seriesplot x=age y=mq&year./ lineattrs=(color=blue);
                                        seriesplot x=age y=fq&year./ lineattrs=(color=red);
                                endlayout;
                                layout overlay/yaxisopts=(label='live population');
                                        seriesplot x=age y=tl&year./ lineattrs=(color=black) ;
                                        seriesplot x=age y=ml&year./ lineattrs=(color=blue);
                                        seriesplot x=age y=fl&year./ lineattrs=(color=red);
                                endlayout;
                                layout overlay/yaxisopts=(label='death population');
                                        seriesplot x=age y=td&year./ lineattrs=(color=black);
                                        seriesplot x=age y=md&year./ lineattrs=(color=blue);
                                        seriesplot x=age y=fd&year./ lineattrs=(color=red);
                                endlayout;
                                layout overlay/yaxisopts=(label='life expectancy');
                                        seriesplot x=age y=te&year./ lineattrs=(color=black) ;
                                        seriesplot x=age y=me&year./ lineattrs=(color=blue);
                                        seriesplot x=age y=fe&year./ lineattrs=(color=red);
                                endlayout;
                        endlayout;
                endgraph;
        end;
run;
proc sgrender data=chapter5 template=lt;
run;
%MEND PLOT;
/***********************************************************************************************************************/
/***********************************************************************************************************************/
/******************************    CHOOSE THE LIFE TABLE CALCULATING METHOD    *****************************************/
/**************************************   FALLER METHOD / COALE METHOD    **********************************************/
/***********************************************************************************************************************/
/***********************************************************************************************************************/
%LIFETABLE_FALLER(t,1998);
%LIFETABLE_FALLER(m,1998);
%LIFETABLE_FALLER(f,1998);
%PLOT(1998);
%LIFETABLE_COALE(t,1989);
%LIFETABLE_COALE(m,1989);
%LIFETABLE_COALE(f,1989);
%plot(1989);
多多指教!

使用道具

地板
davinci37 发表于 2012-8-7 12:19:16 |只看作者 |坛友微信交流群

/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*********** 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;
多多指教!

使用道具

7
davinci37 发表于 2012-8-7 12:20:10 |只看作者 |坛友微信交流群
/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*****************************  Draw a population pyramid with the dataset chapter2  *******************************/
/*******************************************************************************************************************/
/*******************************************************************************************************************/

title 'THE POPULATION PYRAMID';
proc template;
define statgraph pyramid;
        begingraph/ designwidth=1280 designheight=960;
                entrytitle "THE POPULATION PYRAMID FOR YEAR &year.";
                layout lattice/ columns=2 rows=1 columngutter=0;
                        /*--- define the Left side for FEMALE ---*/
                        layout overlay/ xaxisopts=(reverse=on label='FEMALE' )
                                                        yaxisopts=(label='AGE' display=( LABEL LINE TICKS TICKVALUES));
                                barchart x=age y=fpop&year./orient=horizontal name='female' legendlabel='female' fillattrs=(color=red);
                        endlayout;
                        /*--- define the Right side for MALE ---*/
                        layout overlay/ xaxisopts=(label='MALE')
                                                    yaxisopts=(display=( LINE ));
                                barchart x=age y=mpop&year./orient=horizontal name='male' legendlabel='male' fillattrs=(color=blue);
                        endlayout;
                        /*--------------------------------------*/
                        sidebar;
                        discretelegend 'female''male'/across=2;
                        endsidebar;
                endlayout;
        endgraph;
end;
run;
proc sgrender data=chapter2 template=pyramid;
run;
%MEND CHAPTER2;
%CHAPTER2(2009);
%CHAPTER2(1999);



/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*************************************  CALCULATE THE UN AGE-SEX ACCURACY INDEX  ***********************************/
/******** The data file is placed at "e:\Population according to age (5-year) and gender by area 2009.txt"  ********/
/******** The UN INDEX calculates the age 0-74********/
/*******************************************************************************************************************/
/*******************************************************************************************************************
title 'U.N.Age-Sex Accuracy Index';
data unindex;
        infile  'e:\Population according to age (5-year) and gender by area 2009.txt'
        delimiter='09'x linesize=500;
        input (c_tpop c_mpop c_fpop)($) @@;
        age=(_n_-1)*5;
        tpop=input(compress(c_tpop),best.);
        mpop=input(compress(c_Mpop),best.);
        fpop=input(compress(c_Fpop),best.);
        if age<75 then output;
run;
data unindex;
        set unindex end=end_of_dataset;
        sex_ratio=mpop/fpop;
        diff_sr=(sex_ratio-lag(sex_ratio))*100;
        cml_diff_sr +diff_sr;
        un_sr=abs(cml_diff_sr)/15;

        lag_mpop=lag(mpop);
        lag2_mpop=lag2(mpop);

        lag_fpop=lag(fpop);
        lag2_fpop=lag2(fpop);

        D_ar_m=abs(300*lag_mpop/(mpop+lag_mpop+lag2_mpop)-100);
        un_ar_m +(D_ar_m/15);
        D_ar_f=abs(300*lag_fpop/(fpop+lag_fpop+lag2_fpop)-100);
        un_ar_f +(D_ar_f/15);

        if         end_of_dataset then do;
                UN_index=sum(un_sr,un_ar_m,un_ar_f);
                file print;
                put ////
                        @10 'U.N.Age-Sex Accuracy Index'
                        /60*'*'
                        //@5 'The U.N.Age-Sex Accuracy Index is ' un_index
                        //60*'*'
                        /'If the index is lower than 9, it means the data having high quality!';
        end;
run;
*******************************************************************************************************************/
/*******************************************************************************************************************/


不一定对,供楼主和大家参考吧……
多多指教!

使用道具

8
你猜~~~ 发表于 2012-8-7 13:10:21 |只看作者 |坛友微信交流群
davinci37 发表于 2012-8-7 12:20
/*************************************************************************************************** ...
太牛了。。。。学习!

使用道具

9
llkknnllyytt 发表于 2015-10-9 15:43:26 |只看作者 |坛友微信交流群
请问你最后怎么算的?我也想用寿命表法

使用道具

10
llkknnllyytt 发表于 2015-10-9 15:45:00 |只看作者 |坛友微信交流群
davinci37 发表于 2012-8-7 12:19
/************************************************************************************************* ...
呀,太厉害了,这是怎么弄的,能不能教教我

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-26 21:50