Chapter 16: Using Lookup Tables to Match Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Arrays.
Performing Queries Using PROC SQL Chapter 1 1 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
Chapter 9: Arrays and Strings
Chapter 8 Arrays and Strings
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Chapter 9 Introduction to Arrays
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
More Arrays Length, constants, and arrays of arrays By Greg Butler.
Java Unit 9: Arrays Declaring and Processing Arrays.
Chapter 10:Processing Macro Variables at Execution Time 1 STAT 541 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
1 Chapter 4: Introduction to Lookup Techniques 4.1 Introduction to Lookup Techniques 4.2 In-Memory Lookup Techniques 4.3 Disk Storage Techniques.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina Chapter 17 supplement: Review of Formatting Data STAT 541.
Chapter 8 Arrays Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Chapter 16 Processing Variables with Arrays Objectives Group variables into one- and two-dimensional arrays Perform an action on array elements Create.
Chapter 15: Combining Data Horizontally 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 8 Arrays and Strings
Array Processing.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
Introduction to Using the Data Step Hash Object with Large Data Sets Richard Allen Peak Stat.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Chapter 22: Using Best Practices 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
IN THE NAME OF ALLAH WHO IS THE MOST BENEFICENT AND MOST MERCIFUL.
Chapter 17: Formatting Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
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.
Chapter 4: Combining Tables Vertically using PROC SQL 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Arrays.
CSCI 130 More on Arrays. Multi-dimensional Arrays Multi - Dimensional arrays: –have more than one subscript –can be directly initialized –can be initialized.
Chapter 17 Supplement: Alternatives to IF-THEN/ELSE Processing STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South.
Module 1: Array ITEI222 - Advance Programming Language.
Chapter 23: Selecting Efficient Sorting Strategies 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 21: Controlling Data Storage Space 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Chapter 6: Modifying and Combining Data Sets  The SET statement is a powerful statement in the DATA step DATA newdatasetname; SET olddatasetname;.. run;
Chapter 14: Combining Data Vertically 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
Online Programming| Online Training| Real Time Projects | Certifications |Online Classes| Corporate Training |Jobs| CONTACT US: STANSYS SOFTWARE SOLUTIONS.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 8, 13, & 24 By Tasha Chapman, Oregon Health Authority.
Relational and Logical Operators EE 201 1C7-2 Spring 2012.
SAS Certification Prep Guide Chapter 7 Creating and Applying User-Defined Formats.
Two-Dimensional Arrays
Computer Programming BCT 1113
Chapter 2: Getting Data into SAS
Chapter 3: Working With Your Data
Chapter 5: Arrays: Lists and Tables
Chapter 24 (4th ed.): Creating Functions
Data Types and Data Structures
MSIS 655 Advanced Business Applications Programming
Multidimensional array
Arrays Week 2.
Arrays An array is a grouping of elements of the same type that share a common base name Can have any number of elements in the array Individual elements.
Use of PROC TABULATE Out File to Customize Tables
CIS16 Application Development and Programming using Visual Basic.net
Presentation transcript:

Chapter 16: Using Lookup Tables to Match Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina

2 Using Lookup Tables to Match Data Multidimensional arrays Multidimensional arrays PROC TRANSPOSE PROC TRANSPOSE Hash objects Hash objects

3 Using Multidimensional Arrays ARRAY array-name [rows, cols,…] ARRAY array-name [rows, cols,…] { subscript } ; array-name names the array array-name names the array rows specifies the number of elements in a row arrangement rows specifies the number of elements in a row arrangement cols specifies the number of elements in a column arrangement cols specifies the number of elements in a column arrangement array-elements names the variables that make up the array array-elements names the variables that make up the array initial values specifies initial values for the corresponding elements in the array that are separated by commas or spaces initial values specifies initial values for the corresponding elements in the array that are separated by commas or spaces

When Working with Arrays The name of the array cannot be the name of a SAS variable in the DATA step. The name of the array cannot be the name of a SAS variable in the DATA step. The variables listed as array elements must all be the same type (either all numeric or all character). The variables listed as array elements must all be the same type (either all numeric or all character). The initial values specified can be numbers or character strings. Enclose all character strings in quotation marks. The initial values specified can be numbers or character strings. Enclose all character strings in quotation marks.

Keyword _TEMPORARY_ The keyword can be used in lieu of listing array-elements in the syntax, which would avoid creating new data set variables. Only temporary elements are produced using this keyword. The keyword can be used in lieu of listing array-elements in the syntax, which would avoid creating new data set variables. Only temporary elements are produced using this keyword. The temporary elements behave like DATA SET variables, but they don’t have names. Refer to the elements using the array name and dimension. Because they are not DATA set variables, they do not appear in the output data set. The temporary elements behave like DATA SET variables, but they don’t have names. Refer to the elements using the array name and dimension. Because they are not DATA set variables, they do not appear in the output data set.

6 Scoring Example with 2-Dimensional SAS Array data one; input age score; array answer {13:15,1:5} _temporary_ ( ); adjusted = answer(age,score); Adjusted Score Raw Score on a Test Rule for Obtaining Adjusted ScoreAge12345 raw score + 3 (not to exceed 5) raw score +2 (not to exceed 5) raw score + 1 (not to exceed 5)

proc format; invalue gender 'F'=1 'M'=2; invalue age 12.5=1 13.0=2 13.5=3; data one; set inputdata; array answer {1:2,0:3,0:6} _temporary_ ( ); adjusted=answer(input(sex,gender.), input(age,age.),score); Scoring Example with 3-Dimensional SAS Array Adjusted Score Female Student’s Raw Score Age Adjusted Score Male Student’s Raw Score Age Used INPUT function and informats to specify correct array index values.

Using Stored Array Values Arrays can be stored in a data set. Reasons for doing so are: Arrays can be stored in a data set. Reasons for doing so are: –There might be too many values to initialize easily in the array. –The values change frequently. –The same values are used in many programs. –Example

Using Stored Array Values data twoadj (keep=age score finalscore); array adj{13:15,5} _temporary_; if _n_=1 then do i=1 to 3; set lookup;

Using Stored Array Values array adjscore{*} adjscore1-adjscore5; do j=1 to dim(adjscore); adj{age,j}=adjscore{j}; end; end; set two; finalscore=adj{age,score};

Using PROC TRANSPOSE PROC TRANSPOSE transforms horizontal data sets to vertical data sets and vice versa PROC TRANSPOSE transforms horizontal data sets to vertical data sets and vice versa This makes it ideal for match-merging data stored in different formats This makes it ideal for match-merging data stored in different formats Remember that PROC TRANSPOSE requires much “clean-up” of intermediate data sets Remember that PROC TRANSPOSE requires much “clean-up” of intermediate data sets

Using PROC TRANSPOSE IDLength (mm) Weight (g) Age Weight Length < >2500 < >

Using PROC TRANSPOSE data agechart; input length weight1-weight5; proc sort data=agechart; by length; proc transpose data=agechart out=tchart (rename=(age1=age)) name=weight prefix=age; by length;

Using Hash Objects Temporary storage object Temporary storage object Flexible formatting and indexing Flexible formatting and indexing Remember that PROC TRANSPOSE requires much “clean-up” of intermediate data sets Remember that PROC TRANSPOSE requires much “clean-up” of intermediate data sets

Hash Object Structure Key component Key component –must be unique –maps data values to data set Data component Data component –“ragged array” of numeric or character values Is a DATA step object with specific attributes and methods Is a DATA step object with specific attributes and methods

Hash Object There are several steps to creation of a hash object There are several steps to creation of a hash object –DECLARE (i.e., define) the hash object –Define and load keys and data Matched data can then be retrieved Matched data can then be retrieved

Hash Object Gym members example Gym members example –Essentially a match merge –The book uses the data component more actively than in this example

Hash Object data workout; data workout; format name $20.; format name $20.; if _N_=1 then do; if _N_=1 then do; declare hash members(); declare hash members(); members.definekey("id"); members.definekey("id"); members.definedata("name"); members.definedata("name"); members.definedone(); members.definedone(); call missing(id,name); call missing(id,name); members.add(key:787,data:'Sam Crump'); members.add(key:787,data:'Sam Crump'); … members.add(key:9877,data:'Ron cole'); members.add(key:9877,data:'Ron cole'); end; end; set attendance; set attendance; members.find(); members.find(); run; run;

Hash Object Hash objects can also be retrieved from existing SAS data sets Hash objects can also be retrieved from existing SAS data sets –Keys can be used to retrieve data values for more than one variable –Keys can be assigned to more than one data component