暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

NHANES数据库介绍及使用(一)--入门必备小知识

月明学习小铺 2021-07-21
4243

    01  NHANES数据库介绍


  • NHANES是比较有名的公共数据库,虽然已经有前人发过不少文章。但主要肯挖掘,还是有好文章产出。(以一篇BMJ文章为例:Weight change across adulthood in relation to all cause and cause specific mortality: prospective cohort study,真正诠释了啥叫不起眼的数据发大文章,所以说重要的还是idea)


  • 美国国家健康与营养调查( NHANES, National Health and Nutrition Examination Survey)是一项基于人群的横断面调查,旨在收集有关美国家庭人口健康和营养的信息。项目每年调查一个全国代表性的样本,约5000人,这些人群位于全国各县。NHANES访谈部分包括人口统计学、社会经济学、饮食和健康相关问题。体检部分包括生理测量、实验室检查等内容。


  • 当然介绍的再多都不如自己去网站逛一逛https://www.cdc.gov/nchs/nhanes/index.htm



    02  NHANES数据库使用教程(以SAS为例)


  • 下载数据:

    以2005-2006的人口学数据为例,点击画红框的区域即可下载,数据为xpt格式



  • 代码下载:

      filename xptIn url "https://wwwn.cdc.gov/nchs/nhanes/2015-2016/DEMO_I.xpt"; 
      libname xptIn xport;


    • 导入数据:

       (1) 网页下载数据集导入:


      libname XP xport "C:\NHANES\DATA\DEMO_I.xpt"; /*改成相应的硬盘地址*/
      data demo_i;
      set xp.demo_i;
      run; /*复制到work数据集,也就是临时数据集*/
      data mydata.demo_i;
      set xpt.demo_i;
      run; /*复制到mydata数据集,也就是永久数据集*/


         (2) 下载数据集导入:(只需要复制的步骤)


        data demo_i;
        set xp.demo_i;
        run; /*复制到work数据集,也就是临时数据集*/
        data mydata.demo_i;
        set xpt.demo_i;
        run; /*复制到mydata数据集,也就是永久数据集*/


        • XPT文件格式批量导入(提高效率必备):.xpt扩展也被称为通常由SAS应用创建的数据格式,或许这就是为什么双击xpt文件也能打开的原因(当然双击的效率相较于代码还是略低)
          批量导入的话肯定要用到宏程序(需要修改的地方只有三处,均已中文注释):


          /* The code below creates a transport file in the temp folder for use by the macro */


          libname testlib xport 'D:\NHANES\trans.xpt'; /*修改为存放xpt数据集的硬盘位置*/
          proc copy in=sashelp out=testlib;
          select retail;
          run;


          /* Note: Macro starts here */


          /* Macro using PROC COPY and the XPORT engine for reading transport files*/
          %macro drive(dir,ext,out);

          %let filrf=mydir;

          /* Assigns the fileref of mydir to the directory and opens the directory */
          %let rc=%sysfunc(filename(filrf,&dir));
          %let did=%sysfunc(dopen(&filrf));

          /* Returns the number of members in the directory */
          %let memcnt=%sysfunc(dnum(&did));

          /* Loops through entire directory */
          %do i = 1 %to &memcnt;

          /* Returns the extension from each file */
          %let name=%qscan(%qsysfunc(dread(&did,&i)),-1,.);

          /* Checks to see if file contains an extension */
          %if %qupcase(%qsysfunc(dread(&did,&i))) ne %qupcase(&ext) %then %do;

          /* Checks to see if the extension matches the parameter value */
          /* If condition is true, submit PROC COPY statement */
          %if (%superq(ext) ne and %qupcase(&name) = %qupcase(&ext)) or
          (%superq(ext) = and %superq(name) ne) %then %do;

          libname old xport "&dir.\%qsysfunc(dread(&did,&i))";
          libname new "&out";
          proc copy in=old out=new;
          run;
          %end;
          %end;
          %end;

          /* Close the directory */
          %let rc=%sysfunc(dclose(&did));
          /* END MACRO */
          %mend drive;


          /* Macro call */


          /*First parameter is the source folder, the second parameter is extension being */
          /*searched for, and the third parameter is the target directory for the */
          /*converted files. */


          %drive(D:\NHANES,xpt,D:\NHANES\) /*前后修改为存放xpt数据集的硬盘位置,后一个多一斜杠*/



              03  下一期内容预告


          • 介绍数据集以及研究设计基础知识及权重的使用



             04  参考内容


          郭晓娟, 田国祥, 等. NHANES项目介绍及数据提取流程.[J]. 中国循证心血管医学杂志, 2019, 6(11):654-657. https://wwwn.cdc.gov/nchs/data/tutorials/file_download_import_SAS.sas https://support.sas.com/kb/33/918.html https://www.cdc.gov/nchs/nhanes/index.htm https://www.reviversoft.com/zh-cn/file-extensions/xpt






          文章转载自月明学习小铺,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

          评论