1. NHanes數(shù)據(jù)庫(kù)介紹
- NHanes是比較有名的公共數(shù)據(jù)庫(kù),雖然已經(jīng)有前人發(fā)過(guò)不少文章显歧。但主要肯挖掘仪或,還是有好文章產(chǎn)出。(以一篇BMJ文章為例:Weight change across adulthood in relation to all cause and
cause specific mortality: prospective cohort study士骤,真正詮釋了啥叫不起眼的數(shù)據(jù)發(fā)大文章范删,所以說(shuō)重要的還是idea) - 美國(guó)國(guó)家健康與營(yíng)養(yǎng)調(diào)查( NHANES, National Health and Nutrition Examination Survey)是一項(xiàng)基于人群的橫斷面調(diào)查,旨在收集有關(guān)美
國(guó)家庭人口健康和營(yíng)養(yǎng)的信息拷肌。項(xiàng)目每年調(diào)查一個(gè)全國(guó)代表性的樣本到旦,約5000人,這些人群位于全國(guó)各縣巨缘。NHANES訪談部分包括人口統(tǒng)計(jì)學(xué)添忘、社會(huì)經(jīng)濟(jì)學(xué)、飲食和健康相關(guān)問(wèn)題若锁。體檢部分包括生理測(cè)量搁骑、實(shí)驗(yàn)室檢查等內(nèi)容。 - 當(dāng)然介紹的再多都不如自己去網(wǎng)站逛一逛https://www.cdc.gov/nchs/nhanes/index.htm
2. NHanes數(shù)據(jù)庫(kù)使用教程(以SAS為例)
-
下載數(shù)據(jù):
(1) 網(wǎng)頁(yè)直接下載:
(2) 代碼下載:
filename xptIn url "https://wwwn.cdc.gov/nchs/nhanes/2015-2016/DEMO_I.xpt";
libname xptIn xport;
- 導(dǎo)入數(shù)據(jù):
(1) 網(wǎng)頁(yè)下載數(shù)據(jù)集導(dǎo)入:
libname XP xport "C:\NHANES\DATA\DEMO_I.xpt"; /*改成相應(yīng)的硬盤地址*/
data demo_i;
set xp.demo_i;
run; /*復(fù)制到work數(shù)據(jù)集,也就是臨時(shí)數(shù)據(jù)集*/
data mydata.demo_i;
set xpt.demo_i;
run; /*復(fù)制到mydata數(shù)據(jù)集仰冠,也就是永久數(shù)據(jù)集*/
(2) 下載數(shù)據(jù)集導(dǎo)入:(只需要復(fù)制的步驟)
data demo_i;
set xp.demo_i;
run; /*復(fù)制到work數(shù)據(jù)集乏冀,也就是臨時(shí)數(shù)據(jù)集*/
data mydata.demo_i;
set xpt.demo_i;
run; /*復(fù)制到mydata數(shù)據(jù)集,也就是永久數(shù)據(jù)集*/
- XPT文件格式批量導(dǎo)入(提高效率必備):.xpt擴(kuò)展也被稱為通常由SAS應(yīng)用創(chuàng)建的數(shù)據(jù)格式洋只,或許這就是為什么雙擊xpt文件也能打開(kāi)的原因(當(dāng)然雙擊的效率相較于代碼還是略低)
批量導(dǎo)入的話肯定要用到宏程序(需要修改的地方只有三處辆沦,均已中文注釋):
/* The code below creates a transport file in the temp folder for use by the macro */
libname testlib xport 'D:\NHANES\trans.xpt'; /*修改為存放xpt數(shù)據(jù)集的硬盤位置*/
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數(shù)據(jù)集的硬盤位置,后一個(gè)多一斜杠*/
3. 下一期內(nèi)容預(yù)告
介紹數(shù)據(jù)集以及研究設(shè)計(jì)基礎(chǔ)知識(shí)及權(quán)重的使用
4. 參考內(nèi)容
郭曉娟, 田國(guó)祥, 等. NHANES項(xiàng)目介紹及數(shù)據(jù)提取流程.[J]. 中國(guó)循證心血管醫(yī)學(xué)雜志, 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
免費(fèi)的贊不要忘記點(diǎn)一波木张,在此謝過(guò)~