PROC SQL. By Becky Leung Alberta Health Services. Calgary SAS User Group Meeting Wednesday, October 08, 2014

Similar documents
McLean ebasis plus TM

FGSZ Zrt. from 28 February 2019 till 29 February 2020 AUCTION CALENDAR: YEARLY YEARLY BUNDLED AT CROSS BORDER POINTS

Breast Test Wales Screening Division Public Health Wales

GP encounter data to assess vaccine safety. Rob Menzies, Lieu Trinh, Clayton Chiu, Aditi Dey, Kristine Macartney, Peter McIntyre NCIRS

Overview of the Radiation Exposure Doses of the Workers at Fukushima Daiichi Nuclear Power Station

Blood Alcohol Levels for Fatally Injured Drivers

Quit Rates of New York State Smokers

Crisis Connections Crisis Line Phone Worker Training (Online/Onsite) Winter 2019

CryoSat-2 SARin mode over great rivers

Seasonality of influenza activity in Hong Kong and its association with meteorological variations

BLOOD ALCOHOL LEVELS FOR FATALLY INJURED DRIVERS

Flu Watch. MMWR Week 3: January 14 to January 20, and Deaths. Virologic Surveillance. Influenza-Like Illness Surveillance

Consultant-led Referral to Treatment (RTT) waiting times collection timetable: outcome of consultation

Flu Watch. MMWR Week 4: January 21 to January 27, and Deaths. Virologic Surveillance. Influenza-Like Illness Surveillance

Alberta Health. Seasonal Influenza in Alberta. 2016/2017 Season. Analytics and Performance Reporting Branch

BJA Performance Measures

BREATH AND BLOOD ALCOHOL STATISTICS

18 Week 92% Open Pathway Recovery Plan and Backlog Clearance

Date : September Permit/License or Registration Application. Permit/License/ Notification/ Registration Description. Remark

Magellan s Transport Route Lead Monitoring Program

INTERNATIONAL LIPOPROTEIN STANDARDIZATION FORUM Fasting Time and Lipid Levels in a Community-Based Population: A Crosssectional

Avian influenza in poultry, wild and captive birds (AI)

The PROMs Programme in the NHS in England

FIDS Symposium The River Bender

Judy Li Nick Chen The Quit Group

Hand, Foot, and Mouth Disease Situation Update. Hand, Foot, and Mouth Disease surveillance summary

Update on Pandemic H1N1 2009: Oman

CAPL 2 Questionnaire

An Updated Approach to Colon Cancer Screening and Prevention

Sleep Market Panel. Results for June 2015

Durham Region Influenza Bulletin: 2017/18 Influenza Season

Clostridium difficile (C. difficile) and Staphylococcus aureus bacteraemia (MRSA and MSSA) Bi-annual Report. Surveillance: Report:

Kansas EMS Naloxone (Narcan) Administration

JOHN GEORGE PAVILION

Chi-Square Goodness-of-Fit Test

Complete Central Registry Treatment Information Requires Ongoing Reporting and Consolidation Well Beyond 6-Month Reporting

SUPPLIER/MANUFACTURER PERFORMANCE REPORT

Winter Holiday Suicide Myth Continues to be Reinforced in Press Annenberg Public Policy Center Study Finds

From Analytics to Action

APPENDIX ONE. 1 st Appointment (Non-admitted) recovery trajectories

Curators of the University of Missouri - Combined January 1, 2016 through December 31, 2016

March 2012: Next Review September 2012

GREENWOOD PUBLIC SCHOOL DISTRICT PHYSICAL EDUCATION

Implementing Rapid Response Teams (RRT) National Call September 13, 2007

Dementia Content Report January Produced By The NHS Choices Reporting Team

Figure 1: Quantity Dispensed/100 Members (Ambien and Sonata on left axis)

Source URL (modified on :54): Links [1]

Published by the Pharmaceutical Services Division to provide information for British Columbia s health care providers

Dementia Content Report May Produced By The NHS Choices Reporting Team

Tri-County Opioid Safety Coalition Data Brief December 2017 Clackamas, Multnomah, and Washington Counties

FAQs about Provider Profiles on Breast Cancer Screenings (Mammography) Q: Who receives a profile on breast cancer screenings (mammograms)?

IMPLEMENTING RECOVERY ORIENTED CLINICAL SERVICES IN OPIOID TREATMENT PROGRAMS PILOT UPDATE. A Clinical Quality Improvement Program

Empowering Weight Loss Charts & Logs Healthy Weight Chart Cholesterol Chart Blood Pressure Chart Exercise Calorie Burning Chart

Improving care of HIV-infected breastfeeding

Education around PML risk and monitoring at NHNN Queen Square MS Centre

Understanding the Role of Palliative Care in the Treatment of Cancer Patients

Analysis of Meter Reading Validation Tolerances proposed by Project Nexus

Table.'Outbreaks'from'Unpasteurized'(Raw)'Milk'and'non<Mexican'Style'Raw'Milk'Cheeses,'United'States,' 1998<2011.*'

TRANSFORMING STROKE CARE IN THE CAPITAL: THE LONDON STROKE STRATEGY

Achieving Performance Excellence Using Emotional Intelligence

Alberta Health. Seasonal Influenza in Alberta Season. Analytics and Performance Reporting Branch

Can home care reduce the risk of emergency readmissions of older people?

Implementation of an Interprofessional Team to Prevent Inpatient Hypoglycemic Events. September 13, 2016

Data Visualization - Basics

Curators of the University of Missouri - Combined January 01, 2013 through December 31, 2013 Cost Management Report

FIT Overview. Objectives 6/23/2014

Alcohol & Drugs. Contents:

HIV POSITIVE YOUTH: LINKAGE & RETENTION IN CARE

Region of Waterloo Public Health and Emergency Services Infectious Diseases, Dental, and Sexual Health

Weekly Influenza News 2016/17 Season. Communicable Disease Surveillance Unit. Summary of Influenza Activity in Toronto for Week 43

To view past issues, go to: The New 13-Valent Pneumococcal Conjugate Vaccine (PCV13)

Successful Falls Prevention in Aged Persons Mental Health. Reducing the risk and decreasing severity of outcome

Description +/- Balance Description +/- Balance

National Data Analysis

GSK Medicine: Study No.: Title: Rationale: Study Period Objectives: Indication: Study Investigators/Centers: Research Methods: Data Source:

STRENGTHENING THE COORDINATION, DELIVERY AND MONITORING OF HIV AND AIDS SERVICES IN MALAWI THROUGH FAITH-BASED INSTITUTIONS.

HRS 2010: Module 2 Health Literacy V000 BRANCHPOINT: IF THIS IS NOT A SELF-RESPONDENT (A009/A155 NOT 1), GO TO END OF MODULES

CURRICULUM PACING CHART ACES Subject: Science-Second Grade

TB Outbreak in a Homeless Shelter

Bibliographic Information Service of Health Sciences in Japan

EQAS. Hemoglobin Program (BC80) Cycle 12: December 2014 December 2015 Sample No: 1 Sample Date: 17 Dec 14. Exceptions. Customer Information

BIOL1. (JUN13BIOL101) WMP/Jun13/BIOL1. General Certificate of Education Advanced Subsidiary Examination June Unit 1 Biology and disease

NORTHERN HEALTH AND SOCIAL CARE TRUST. Waiting Times Summary Report

Has the UK had a double epidemic?

June 28, 2008 General Assembly, Fort Lauderdale Presented by Linda Laskowski Unitarian Universalist Church of Berkeley

NEW PSYCHOACTIVE SUBSTANCES (LEGAL HIGHS) INFORMATION SUPPORTING RAG ANALYSIS

South Plains Emergency Medical Services, Inc. P.O. Box Lubbock, Texas 79453

Supplementary Online Content

Outbreak Response/Epidemiology Influenza Weekly Report Arkansas

Sexual Health Content Report June Produced By The NHS Choices Reporting Team

Cincinnati Children s Hospital Medical Center PHO/OVPCA Constipation Initiative Monthly Report February 2018

Wyoming Quit Tobacco Program Follow-Up Survey

Impact of National Guidance for Drug Prescribing for Dentistry

Parity: Innovation in Practice

Saskatchewan HIV Strategy: Social Network Approach

Marketing on a Budget: Monthly quit & win challenges to drive quitline utilization. Presenters: John Atkinson & Elizabeth Harvey

Health impact assessment of particulate matter exposure in Pearl River Delta (PRD), China

City of Vancouver s Response to the Opioid Crisis Fire Chief Darrell Reid Vancouver Fire & Rescue Services (VF&RS)

Emergency Department Boarding of Psychiatric Patients in Oregon

Pennine Acute Hospitals NHS Trust. Advancing Quality Results October 2008 to December 2016

Transcription:

PROC SQL By Becky Leung Alberta Health Services Calgary SAS User Group Meeting Wednesday, October 08, 2014

WHAT IS PROC SQL? A Base SAS procedure that combines the functionality of DATA and PROC steps into a single step

WHAT CAN PROC SQL DO? Sort, summarize, subset, join (merge), and concatenate datasets Create new variables and print the results or create a new table or view within one step Retrieve, update and report on information from SAS datasets

SYNTAX PROC SQL; CREATE table-name view-name AS SELECT column(s) FROM table-name view-name WHERE expression GROUP BY columns(s) HAVING expression ORDER BY columns(s) ; QUIT;

MERGING TABLES IN PROC SQL We can merge two tables together within one step We can merge three or more tables together within one step

MERGING TWO TABLES

TABLE A A 1 2 3 4 B TABLE B B 1 2 3 4 C MERGE: ONE TO ONE

TABLE A TABLE B A B B C 1 2 3 4 1 1 1 2 2 3 MERGE: ONE TO MANY 4 TABLE A TABLE B C B B A 1 1 1 2 1 2 3 4 2 3 4 MERGE: MANY TO ONE

TABLE A TABLE B A B B C 1 1 2 2 2 3 4 4 1 1 1 2 2 3 4 MERGE: MANY TO MANY

SYNTAX PROC SQL; CREATE table-name view-name AS SELECT column(s) FROM table-name view-name alias1 JOIN table-name view-name alias2 ON alias1.varible-name EQ alias2.variable-name ; QUIT;

TABLE A: HOSPITAL_ADMISSION OBS # PATIENT_ID HOSPITAL_ADMISSION_DATE 1 1 01JAN13 2 1 03FEB13 3 2 10JAN13 4 2 10MAR13 5 2 13SEP13 6 3 02APR13 7 4 15FEB13 8 4 09DEC13 TABLE B: PATIENT_DEMOGRAPHICS OBS # PATIENT_ID BIRTHDATE CITY HOUSEHOLD_INCOME 1 1 01FEB53 CALGARY 60,000 2 2 22OCT43 CALGARY 100,000 3 3 12MAR43 CALGARY 25,000 4 4 01JUN44 EDMONTON 0 5 5 03JAN44 EDMONTON 130,000

1 3 5 2 4 6 7

SYNTAX MERGING TWO TABLES PROC SQL; CREATE TABLE PATIENT_INFO1 AS SELECT A.*, B.BIRTHDATE FROM HOSPITAL_ADMISSION A LEFT JOIN PATIENT_DEMOGRAPHICS B ON A.PATIENT_ID EQ B.PATIENT_ID; QUIT;

RESULT TABLE: PATIENT_INFO1 OBS # PATIENT_ID HOSPITAL_ADMISSION_DATE BIRTHDATE 1 1 1-Jan-13 1-Feb-53 2 1 3-Feb-13 1-Feb-53 3 2 10-Jan-13 22-Oct-43 4 2 13-Sep-13 22-Oct-43 5 2 10-Mar-13 22-Oct-43 6 3 2-Apr-13 12-Mar-43 7 4 15-Feb-13 1-Jun-44 8 4 9-Dec-13 1-Jun-44

SYNTAX MERGING TWO TABLES PROC SQL; CREATE TABLE PATIENT_INFO2 AS SELECT A.*, B.BIRTHDATE FROM HOSPITAL_ADMISSION A RIGHT JOIN PATIENT_DEMOGRAPHICS B ON A.PATIENT_ID EQ B.PATIENT_ID; QUIT;

RESULT TABLE: PATIENT_INFO2 OBS # PATIENT_ID HOSPITAL_ADMISSION_ DATE BIRTHDATE 1 1 1-Jan-13 1-Feb-53 2 1 3-Feb-13 1-Feb-53 3 2 10-Jan-13 22-Oct-43 4 2 13-Sep-13 22-Oct-43 5 2 10-Mar-13 22-Oct-43 6 3 2-Apr-13 12-Mar-43 7 4 15-Feb-13 1-Jun-44 8 4 9-Dec-13 1-Jun-44 9.. 3-Jan-44

SYNTAX MERGING TWO TABLES PROC SQL; CREATE TABLE PATIENT_INFO3 AS SELECT B.*, A.HOSPITAL_ADMISSION_DATE FROM HOSPITAL_ADMISSION A RIGHT JOIN PATIENT_DEMOGRAPHICS B ON A.PATIENT_ID EQ B.PATIENT_ID; QUIT;

RESULT TABLE: PATIENT_INFO3 OBS # PATIENT_ ID BIRTHDATE CITY HOUSEHOL D_IINCOME HOSPITAL_ ADMISSIO N_DATE 1 1 1-Feb-53 CALGARY 60000 1-Jan-13 2 1 1-Feb-53 CALGARY 60000 3-Feb-13 3 2 22-Oct-43 CALGARY 100000 10-Jan-13 4 2 22-Oct-43 CALGARY 100000 13-Sep-13 5 2 22-Oct-43 CALGARY 100000 10-Mar-13 6 3 12-Mar-43 CALGARY 25000 2-Apr-13 7 4 1-Jun-44 EDMONTON 0 15-Feb-13 8 4 1-Jun-44 EDMONTON 0 9-Dec-13 9 5 3-Jan-44 EDMONTON 130000.

SYNTAX MERGING TWO TABLES PROC SQL; CREATE TABLE PATIENT_INFO3A AS SELECT B.*, A.HOSPITAL_ADMISSION_DATE FROM HOSPITAL_ADMISSION A RIGHT JOIN PATIENT_DEMOGRAPHICS B ON A.PATIENT_ID EQ B.PATIENT_ID WHERE HOUSEHOLD_IINCOME GT 0; QUIT;

RESULT TABLE: PATIENT_INFO3A OBS # PATIENT_ ID BIRTHDATE CITY HOUSEHOL D_IINCOME HOSPITAL_ ADMISSIO N_DATE 1 1 1-Feb-53 CALGARY 60000 1-Jan-13 2 1 1-Feb-53 CALGARY 60000 3-Feb-13 3 2 22-Oct-43 CALGARY 100000 10-Jan-13 4 2 22-Oct-43 CALGARY 100000 13-Sep-13 5 2 22-Oct-43 CALGARY 100000 10-Mar-13 6 3 12-Mar-43 CALGARY 25000 2-Apr-13 7 5 3-Jan-44 EDMONTON 130000.

SYNTAX MERGING TWO TABLES PROC SQL; CREATE TABLE PATIENT_INFO4 AS SELECT A.PATIENT_ID AS PATIENT_ID_A LABEL="PATIENT ID A", B.PATIENT_ID AS PATIENT_ID_B LABEL="PATIENT ID B", HOSPITAL_ADMISSION_DATE LABEL="HOSPITAL ADMISSION DATE", B.BIRTHDATE LABEL="PATIENT BIRTHDATE FORMAT=DATE11. FROM HOSPITAL_ADMISSION A INNER JOIN PATIENT_DEMOGRAPHICS B ON A.PATIENT_ID EQ B.PATIENT_ID; QUIT;

RESULT TABLE: PATIENT_INFO4 OBS # PATIENT ID A PATIENT ID B HOSPITAL ADMISSION DATE PATIENT BIRTHDATE 1 1 1 1-Jan-13 1-Feb-1953 2 1 1 3-Feb-13 1-Feb-1953 3 2 2 10-Jan-13 22-Oct-1943 4 2 2 13-Sep-13 22-Oct-1943 5 2 2 10-Mar-13 22-Oct-1943 6 3 3 2-Apr-13 12-Mar-1943 7 4 4 15-Feb-13 1-Jun-1944 8 4 4 9-Dec-13 1-Jun-1944

SYNTAX MERGING TWO TABLES PROC SQL; CREATE TABLE PATIENT_INFO5 AS SELECT FROM QUIT; A.PATIENT_ID AS PATIENT_ID_A LABEL="PATIENT ID A", B.PATIENT_ID AS PATIENT_ID_B LABEL="PATIENT ID B", HOSPITAL_ADMISSION_DATE LABEL="HOSPITAL ADMISSION DATE", B.BIRTHDATE LABEL= PATIENT BIRTHDATE FORMAT=DATE11., FLOOR((HOSPITAL_ADMISSION_DATE - BIRTHDATE)/365) AS AGE LABEL="PATIENT AGE" HOSPITAL_ADMISSION A FULL OUTER JOIN PATIENT_DEMOGRAPHICS B ON A.PATIENT_ID EQ B.PATIENT_ID;

RESULT TABLE: PATIENT_INFO5 OBS # PATIENT ID A PATIENT ID B HOSPITAL ADMISSION DATE PATIENT BIRTHDATE 1 1 1 1-Jan-13 1-Feb-1953 59 2 1 1 3-Feb-13 1-Feb-1953 60 3 2 2 10-Jan-13 22-Oct-1943 69 4 2 2 13-Sep-13 22-Oct-1943 69 5 2 2 10-Mar-13 22-Oct-1943 69 6 3 3 2-Apr-13 12-Mar-1943 70 7 4 4 15-Feb-13 1-Jun-1944 68 8 4 4 9-Dec-13 1-Jun-1944 69 9. 5. 3-Jan-1944. PATIENT AGE

REFERENCES http://www2.sas.com/proceedings/sugi27/p191-27.pdf

THANK YOU