1 Using the Magical Keyword “INTO” in PROC SQL Thiru Satchi Blue Cross and Blue Shield of Massachusetts Boston Area SAS Users Group April 5, 1999.

Slides:



Advertisements
Similar presentations
Haas MFE SAS Workshop Lecture 3:
Advertisements

DIVERSE REPORT GENERATION By Chris Speck PAREXEL International Durham, NC.
The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Combining Lags and Arrays [and a little macro] Lynn Lethbridge SHRUG OCT 28, 2011.
A guide to the unknown…  A dataset is longitudinal if it tracks the same type of information on the same subjects at multiple points in time or space.
Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.
Chapter 28 Design of Experiments (DOE). Objectives Define basic design of experiments (DOE) terminology. Apply DOE principles. Plan, organize, and evaluate.
Crawler-Based Search Engine By: Bryan Chapman, Ryan Caplet, Morris Wright.
Mini-Pascal Compiling Mini-Pascal (MPC) language
Basic And Advanced SAS Programming
PROC SQL – Select Codes To Master For Power Programming Codes and Examples from SAS.com Nethra Sambamoorthi, PhD Northwestern University Master of Science.
Let SAS Do the Coding for You! Robert Williams Business Info Analyst Sr. WellPoint Inc.
Chapter 18: Modifying SAS Data Sets and Tracking Changes 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Data Preparation for Analytics Using SAS Gerhard Svolba, Ph.D. Reviewed by Madera Ebby, Ph.D.
Context\Context.wb Library Functions.  Data Driven Programming.  Enhance Existing programs.  Quickly Develop new Programs.  Powerful Set of Library.
SCSUG Avoiding Hand Cramps: Name2 macro and arrays for related variables November 9, am South Center SAS Users Group Austin, Texas.
SAS SQL SAS Seminar Series
Lecture 5 Sorting, Printing, and Summarizing Your Data.
Chapter 9 Producing Descriptive Statistics PROC MEANS; Summarize descriptive statistics for continuous numeric variables. PROC FREQ; Summarize frequency.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
1 Experimental Statistics - week 4 Chapter 8: 1-factor ANOVA models Using SAS.
Class 3 Programming in Visual Basic. Class Objectives Learn about input/output Learn about strings Learn about subroutines Learn about arrays Learn about.
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.
Niraj J. Pandya, Element Technologies Inc., NJ.  Summarize all possible combinations of class level variables even if few categories are altogether missing.
Key Data Management Tasks in Stata
Report Management Using the ODS DOCUMENT Destination and Report Metadata Brit Harvey February 2010.
Chapter 6 SAS ® OLAP Cube Studio. Section 6.1 SAS OLAP Cube Studio Architecture.
Lesson 5 - Topics Formatting Output Working with Dates Reading: LSB:3:8-9; 4:1,5-7; 5:1-4.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
Use the UPDATE statement to: –update a master dataset with new transactions (e.g. a bank account updated regularly with deposits and withdrawals…). Not.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
5/30/2010 SAS Macro Language Group 6 Pradnya Nimkar, Li Lin, Linsong Zhang & Loc Tran.
1 SAS 1-liners SAS Coding Efficiencies. 2 Overview Less is more Always aim for robust, reusable and efficient code Coding efficiency versus processing.
Grant Brown.  AIDS patients – compliance with treatment  Binary response – complied or no  Attempt to find factors associated with better compliance.
1 Efficient SAS Coding with Proc SQL When Proc SQL is Easier than Traditional SAS Approaches Mike Atkinson, May 4, 2005.
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
1 Filling in the blanks with PROC FREQ Bill Klein Ryerson University.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
BMTRY 789 Lecture 10: SAS MACRO Facility Annie N. Simpson, MSc.
End of unit assessment Challenge 1 & 2. Course summary So far in this course you have learnt about and used: Syntax Output to screen (PRINT) Variables.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Lecture 4 Ways to get data into SAS Some practice programming
Practical Uses of the DOW Loop Richard Allen Peak Stat April 8, 2009.
Time Series Data Processes by Tai Yu April 15, 2013.
Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.
FORMAT statements can be used to change the look of your output –if FORMAT is in the DATA step, then the formats are permanent and stored with the dataset.
SHRUG, F EB 2013: N ETWORKING EXERCISE Many Ways to Solve a SAS Problem.
Last Updated : 27 th April 2004 Center of Excellence Data Warehousing Group Teradata RDBMS Concepts.
Gator Engineering Google Code Jam 2015 Copyright © 2008 W. W. Norton & Company. All rights reserved. 1.
Chapter 6: Modifying and Combining Data Sets  The SET statement is a powerful statement in the DATA step DATA newdatasetname; SET olddatasetname;.. run;
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
Online Programming| Online Training| Real Time Projects | Certifications |Online Classes| Corporate Training |Jobs| CONTACT US: STANSYS SOFTWARE SOLUTIONS.
SAS ® Global Forum 2014 March Washington, DC.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 8, 13, & 24 By Tasha Chapman, Oregon Health Authority.
Dynamic SQL Writing Efficient Queries on the Fly ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
Working Efficiently with Large SAS® Datasets Vishal Jain Senior Programmer.
Longitudinal Data Techniques: Looking Across Observations Ronald Cody, Ed.D., Robert Wood Johnson Medical School.
CMS SAS Users Group Conference Learn more about THE POWER TO KNOW ® October 17, 2011 Medicare Payment Standardization Modeling using SAS Enterprise Miner.
Introduction to Programming
Dynamic SQL Writing Efficient Queries on the Fly
Dynamic SQL Writing Efficient Queries on the Fly
Creating Macro Variables in SQL (Review)
Chapter 18: Modifying SAS Data Sets and Tracking Changes
Creating Macro Variables in the DATA Step
3 Iterative Processing.
Producing Descriptive Statistics
Python Basics with Jupyter Notebook
Presentation transcript:

1 Using the Magical Keyword “INTO” in PROC SQL Thiru Satchi Blue Cross and Blue Shield of Massachusetts Boston Area SAS Users Group April 5, 1999

2 Background Valuable resource for creating one or more macro variable made up of values in one step. Overcomes several limitations in hard coding values, including the possibility of typographical errors and resource constraints (i.e., programming time).

3 Objective Develop a code that (1) summarize medical claims data to the patient level by summing the total number of medical visits and corresponding paid amounts. (2) include treatment group(s) that affected each patient in the summary data. (3) accounted for a dynamic data source, yet require minimal maintenance and useful for any analysis.

4 Sample SAS Dataset 1. DATA MASTER; 2. PAT_ID TG_GRP $4. SVC_DT PAID_AMT 2.; 7. DATALINES; 8. P1TG01 01/21/ P1 TG12 02/10/ P1 TG03 03/16/ P1 TG15 03/16/ P1 TG04 05/09/ P1 TG04 05/10/ P1 TG04 05/15/ P1 TG03 01/25/ P1 TG12 11/29/ P1 TG04 01/12/ P1 TG18 12/26/ P1 TG18 12/31/ P1 TG12 01/07/ P1 TG99 05/18/ P2 TG12 07/26/ P2 TG04 10/23/ P2 TG46 11/24/ P2 TG74 12/25/ P2 TG88 03/08/ P2 TG88 02/28/ P2 TG11 12/01/ P2 TG11 12/31/ ;

5 STEP1: Read in the Data PROC MEANS SUM NOPRINT NWAY DATA=MASTER; CLASS PAT_ID TG_GRP; VAR PAID_AMT; OUTPUT OUT=TG_SUM (RENAME=(_FREQ_=VISIT) DROP=_TYPE_) SUM=TOT_AMT; RUN; The first step of this program initially reads in the data, which is then summarized by patient (PAT_ID) and treatment group (TG_GRP) using PROC MEANS. This summary is outputted to a SAS data set called ‘TG_SUM’. In the process, we establish a variable called ‘VISIT’, which is the number of service visits, based on the frequency, or the number of times each unique combination of patient and treatment group occurs. A printout of the TG_SUM data is presented below.

6 SQL List Macro Character Key Variable TREATMENT GROUP SUMMARY BY PATIENT PAT_IDTG_GRPVISITTOT_AMT P1TG01166 P1TG P1TG P1TG12378 P1TG15146 P1TG18295 P1TG99122 P2TG04161 P2TG11279 P2TG12161 P2TG74161 P2TG882107

7 Building Lists of Values Using the “INTO” Host Variable Utilizes the INTO: host-variable in PROC SQL to generate a unique list of treatment groups that are separated by a space. This list is made of only those treatment groups present in the patient population and is stored as a macro variable, ‘TGLIST’. PROC SQL NOPRINT; SELECT DISTINCT TG_GRP INTO: TGLIST SEPERATED BY ’ ' FROM MASTER; %PUT &TGLIST; 1. TG01 TG02 TG03

8 STEP3: Character Key Variable At this step takes the list of all available treatment groups stored in TGLIST and converts them into variables using the array feature. These newly formed variables are assigned with a ‘0’ using a DO LOOP. This DO LOOP works relies on the DIM function, which tracks the number of newly formed variables. It should be noted that this list of dummy variables is generated and applied to all patients, regardless if they are affected by a treatment group or not. DATA NEWDATA (DROP=I); SET TG_SUM; ARRAY TEMP{*} &TGLIST; DO I =1 TO DIM(TEMP); TEMP{I} = 0; END; PROC PRINT DATA=NEWDATA; TITLE "ESTABLISH TREATMENT GROUPS WITH VALUES SET TO ZERO” ; RUN;

9

10 Variations of the SQL List Macro Character Key Variable (continued) This program tags the newly formed variables if the corresponding treatment group is present. This is accomplished with the SAS CEIL and INDEX function, which scans the TGLIST macro variable and populates the variables with a ‘1’. DATA FIXDATA ; SET NEWDATA; ARRAY TEMP{*} &TGLIST; TEMP(CEIL(INDEX("&TGLIST",TRIM(TG_GRP))/ (LENGTH(TG_GRP)+1))) = 1; PROC PRINT DATA=FIXDATA; TITLE "TREATMENT GROUPS ASSIGNED IF CONDITION IS PRESENT”; RUN;

11

12 Variations of the SQL List Macro Character Key Variable (continued) PROC MEANS SUM NOPRINT NWAY DATA = FIXDATA; CLASS PAT_ID ; VAR VISIT TOT_AMT &TGLIST; OUTPUT OUT = PAT_SUM (DROP = _FREQ__TYPE_) SUM = ; RUN; PROC PRINT DATA=PAT_SUM; TITLE "PATIENT SUMMARY REPORT "; RUN; The fifth and final step of this program performs a patient-level summary of the data using PROC MEANS. This summary is then outputted to a separate data set, ‘PAT_SUM’.

13

14 Conclusions “INTO:” host-variable in PROC SQL is a powerful resource that can overcome numerous coding issues. I have illustrated different variations of this host-variable and an example of its application to overcome a typical issue in summarizing a large medical claims data set.

15 Contact