科研信息学

Nhanes数据库介绍及使用(一)

2020-08-23  本文已影响0人  不学临床的医学生

1. NHanes数据库介绍

2. NHanes数据库使用教程(以SAS为例)

filename xptIn url "https://wwwn.cdc.gov/nchs/nhanes/2015-2016/DEMO_I.xpt"; 
libname xptIn xport; 
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数据集,也就是永久数据集*/
/* 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数据集的硬盘位置,后一个多一斜杠*/

3. 下一期内容预告
介绍数据集以及研究设计基础知识及权重的使用

4. 参考内容

郭晓娟, 田国祥, 等. 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

免费的赞不要忘记点一波,在此谢过~

上一篇 下一篇

猜你喜欢

热点阅读