Example, Create an analytic file for Nhanes 1999

Slides:



Advertisements
Similar presentations
SAS Programming:File Merging and Manipulation. Reading External Files (review) data barf; * create the dataset BARF; infile ’s:\mysas\Table7.1'; * open.
Advertisements

Knowing Understanding the Basics Writing your own code part 2 SAS Lab.
Nearest neighbor matching USING THE GREEDY MATCH MACRO Note: Much of the code originally was written by Lori Parsons
P449. p450 Figure 15-1 p451 Figure 15-2 p453 Figure 15-2a p453.
Introduction to SQL Session 1 Retrieving Data From a Single Table.
Basic And Advanced SAS Programming
Using Proc Datasets for Efficiency Originally presented as a Coder’s NESUG2000 by Ken Friedman Reviewed by Karol Katz.
SAS Programming SAS Data Mart. Outline Access different format of data for SAS SAS data mart SAS data manipulation 2.
Data Preparation for Analytics Using SAS Gerhard Svolba, Ph.D. Reviewed by Madera Ebby, Ph.D.
NHANES Analytic Strategies Deanna Kruszon-Moran, MS Centers for Disease Control and Prevention National Center for Health Statistics.
SAS PROC REPORT PROC TABULATE
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
SAS SQL Part 2 Alan Elliott. Dealing with Missing Values Title "Dealing with Missing Values in SQL"; PROC SQL; select INC_KEY,GENDER, RACE, INJTYPE, case.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
Knowing Understanding the Basics Writing your own code SAS Lab.
WWEIA, NHANES Dietary Data: Data Preparation Steps for Dietary Analysis Randy P. LaComb Food Surveys Research Group Beltsville Human Nutrition Research.
Grant Brown.  AIDS patients – compliance with treatment  Binary response – complied or no  Attempt to find factors associated with better compliance.
SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically.
Lesson 8 - Topics Creating SAS datasets from procedures Using ODS and data steps to make reports Using PROC RANK Programs in course notes LSB 4:11;5:3.
SAS Basics. Windows Program Editor Write/edit all your statement here.
An Introduction Katherine Nicholas & Liqiong Fan.
Second Period: PROC TABULATE Jill Casey. Example 1: Simple 2D Table.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 3 & 4 By Tasha Chapman, Oregon Health Authority.
Session 1 Retrieving Data From a Single Table
Session 15 Merging Data in SPSS
Chapter 11 Reading SAS Data
Raw data Log-transformed data Male age log age Female age log age
COP 4540 Database Management
Putting tables together
Basic Queries Specifying Columns
An Introduction to SQL.
SAS Programming I Matthew A. Lanham Doctoral Student
Chapter 18: Modifying SAS Data Sets and Tracking Changes
Deanna Kruszon-Moran, MS
Instructor: Raul Cruz-Cano
Lesson 8 - Topics Creating SAS datasets from procedures
Tamara Arenovich Tony Panzarella
2018 NM Community Survey Data Entry Training
Noncorrelated subquery
Creating the Example Data
Quick Data Summaries in SAS
Demonstrating the Linear Model
Chance to make SAS-L History!
Complete Case Macro.
Grouping Summary Results
Claire Osgood November 2017
How to Create Data Driven Lists
SAS Libname Quiz (You have 5 mins to complete, fill in the blanks)
Inner Joins.
Create a subset of DPC data
Dictionary Tables and Views, obtain information about SAS files
Meta-Analysis Glass (Education Researcher, 5:3-8; 1976) suggested that there were three types of analyses: Primary analysis tests the hypothesis for.
Examining model stability, an example
Combining Data Sets in the DATA step.
Lab 3 and HRP259 Lab and Combining (with SQL)
Use of PROC TABULATE Out File to Customize Tables
Trigger %macro check_trigger_run;
Framingham, Exam 5 subset
Introduction to Subqueries, An Example
Shortcuts for Variable Lists in SAS
Appending and Concatenating Files
Fixed Effects estimate using person level data
A new keyword -- calculated
a useful SAS 9.2 feature I wasn’t aware of *
Introduction to SAS Lecturer: Chu Bin Lin.
Data tmp; do i=1 to 10; output; end; run; proc print data=tmp;
Hans Baumgartner Penn State University
PhilaSUG Spring Meeting June 05, 2019
Writing Robust SAS Macros
Presentation transcript:

Example, Create an analytic file for Nhanes 1999

The Nhanes 1999 data libname nh9Mort "&path/nhanes1999/mortality/sas"; libname nh9ques "&path/nhanes1999/questionnaire/sas"; libname nh9lab "&path/nhanes1999/lab/sas"; libname nh9exam "&path/nhanes1999/exam/sas"; libname nh9demo "&path/nhanes1999/demographics/sas"; libname nh9diet "&path/nhanes1999/dietary/sas";

Concatenating Libnames and a handy use of SQL libname nh9 (nh9demo nh9exam nh9lab nh9mort nh9ques);

Meta Data in SAS, a handy use of PROC SQL

proc sql; describe table dictionary.tables ; select memname,nvar,nobs from dictionary.tables where libname="NH9" quit;

The data for creating the analytic file is on five different datasets. proc contents data=nh9.mortality; proc contents data=nh9.bloodpressure; proc contents data=nh9.demographics; proc contents data=nh9.bodymeasurements; proc contents data=nh9.cholesterolhdl; run;

Mortality Primary Key

From Documentation: Coding for eligstat 1= Eligible 2 =Under age 18, not available for public release1 3 =Ineligible Coding for mortstat 0 Assumed alive 1 Assumed deceased

proc freq data=nh9.mortality; tables eligstat mortstat; run;

Blood Pressure (partial) Primary Key

Check averages proc sql inobs=100; select mean(BPXSY1,BPXSY2,BPXSY3,BPXSY4),BPXSar from nh9.bloodpressure ; quit;

Calculate Averages proc sql ; create table newbp as select mean(BPXSY1,BPXSY2,BPXSY3,BPXSY4) as mnsbp, mean(BPXDI1,BPXDI2,BPXDI3,BPXDI4) as mndbp, seqn from nh9.bloodpressure ; select n(mnsbp) "mnsbp",n(mndbp) "mndbp" from newbp quit;

Calculate averages with data step data newbp( drop=bpxsy1-bpxsy4); set nh9.bloodpressure(keep=seqn bpxsys1-bpxsys4); mnsbp=mean(of BPXSY1-BPXSY4); mndbp=mean(of BPXDI1-BPXDI4); run; proc means data=newbp;

Demographics Figure out which ones desired

proc means data=nh9.demographics; var ri: seqn; run;

Primary Key

From Documentation

From Documentation

From Documentation

Bodymeasurements (partial) Primary Key

CholesterolHdl Primary Key

Data Variable(s) New Variable/recode Mortality mortstat Dead (0,1) Demographics riagendr Male(0,1) RIDAGEYR Age RIDRETH2 Race_ethn Bodymeasurements bmxbmi bmi Bloodpressure BPXSY1-BPXSY4 mnsbp BPXDI1-BPXDI4 mndbp CholesterolHdl LBDHDL hdl LBXTC chol

Doing it in the data step Create five (temporary) datasets Sort and Merge

Create five datasets data mort (drop=mortstat eligstat); set nh9.mortality(keep=seqn eligstat mortstat permth_exm); where eligstat eq 1; dead=mortstat=1; data newbp(drop=bpxsy1-bpxsy4 BPXDI1-BPXDI4); set nh9.bloodpressure(keep=seqn bpxsy1-bpxsy4 BPXDI1-BPXDI4); mnsbp=mean(of BPXSY1-BPXSY4); mndbp=mean(of BPXDI1-BPXDI4); data demog (drop=riagendr); set nh9.demographics (keep=seqn ridageyr riagendr RIDRETH2); male=riagendr=1; rename ridageyr=age ridreth2=race_ethn; data chol; set nh9.cholesterolhdl(keep= seqn LBDHDL LBXTC); rename lbdhdl=hdl lbxtc=chol; data body; set nh9.bodymeasurements(keep=seqn bmxbmi rename=(bmxbmi=bmi)); run;

Sort and Merge proc sort data=mort; by seqn; proc sort data=newbp; proc sort data=demog; proc sort data=chol; proc sort data=body; data analysis; merge mort(in=a) newbp(in=b) demog(in=c) chol(in=d) body(in=e); if a and b and c and d and e; run;

proc contents data=analysis; run;

The same thing in Proc SQL

proc sql; create table analysis as select a.seqn,mortstat=1 as dead,permth_exm, mean(BPXSY1,BPXSY2,BPXSY3,BPXSY4) as mnsbp, mean(BPXDI1,BPXDI2,BPXDI3,BPXDI4) as mndbp, riagendr=1 as male, ridageyr as age, ridreth2 as race_ethn, lbdhdl as hdl, lbxtc as chol, bmxbmi as bmi from nh9.mortality(keep=seqn eligstat mortstat permth_exm) a, nh9.bloodpressure(keep=seqn bpxsy1-bpxsy4 BPXDI1-BPXDI4) b, nh9.demographics (keep=seqn ridageyr riagendr RIDRETH2) c, nh9.bodymeasurements(keep=seqn bmxbmi) d, nh9.cholesterolhdl(keep= seqn LBDHDL LBXTC) e where eligstat eq 1 and a.seqn=b.seqn and b.seqn=c.seqn and c.seqn=d.seqn and d.seqn=e.seqn order by seqn ; quit;