TASS Meeting Using Multiple DOW Loops September 25th, 2009 Using Multiple DOW Loops Dr. Arthur Tabachneck Director, Data Management Idea stolen from a.

Slides:



Advertisements
Similar presentations
Copyright © 2006, SAS Institute Inc. All rights reserved. Think FAST! Use Memory Tables (Hashing) for Faster Merging Gregg P. Snell Data Savant Consulting.
Advertisements

How SAS implements structured programming constructs
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Descriptive Statistics. Descriptive Statistics: Summarizing your data and getting an overview of the dataset  Why do you want to start with Descriptive.
Worst, but still importable data I’ve ever seen Arthur Tabachneck Insurance Bureau of Canada.
Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.
Knowing Understanding the Basics Writing your own code part 2 SAS Lab.
Professional Seminar Northwestern Polytechnic University By Dr. Michael M Cheng.
SAS Programming: Working With Variables. Data Step Manipulations New variables should be created during a Data step Existing variables should be manipulated.
Unit 7: Chance Variation. Repeating with Excel Two EV’s and two SE’s Suppose we know the box (model) of a game, and we make many draws from the box with.
Automagically Copying and Pasting Variable Names Arthur Tabachneck Roger DeAngelis Randy Herbison Insurance Bureau of Canada CompuCraft Inc Westat John.
Enough really good SAS ® tips to fill a book Arthur Tabachneck, President and CEO, myqna.org.
Tables and graphs for frequencies and summary statistics
Variance and Standard Deviation The Expected Value of a random variable gives the average value of the distribution The Standard Deviation shows how spread.
This year’s SGF Arthur Tabachneck Insurance Bureau of Canada.
1 Sociology 601, Class 4: September 10, 2009 Chapter 4: Distributions Probability distributions (4.1) The normal probability distribution (4.2) Sampling.
In this tutorial you will learn how to go from this table to Click here!
Deviation = The sum of the variables on each side of the mean will add up to 0 X
SAS Lecture 5 – Some regression procedures Aidan McDermott, April 25, 2005.
Fundamentals of Statistical Analysis DR. SUREJ P JOHN.
SAS SQL SAS Seminar Series
Multiple Regression. In the previous section, we examined simple regression, which has just one independent variable on the right side of the equation.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
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.
Matlab Programming for Engineers Dr. Nidal Farhat Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Knowing Understanding the Basics Writing your own code SAS Lab.
Mean and Standard Deviation of Grouped Data Make a frequency table Compute the midpoint (x) for each class. Count the number of entries in each class (f).
AP STATS: Take 10 minutes or so to complete your 7.1C quiz.
TASS Meeting Copy and Paste from Excel to SAS September 19th, 2008 Copy and Paste from Excel to SAS Dr. Arthur Tabachneck, Director Data Management with.
Loops Brent M. Dingle Texas A&M University Chapter 7 – part D (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Lecture 8 Simple Linear Regression (cont.). Section Objectives: Statistical model for linear regression Data for simple linear regression Estimation.
Define your Own SAS® Command Line Commands Duong Tran – Independent Contractor, London, UK Define your Own SAS® Command Line Commands Duong Tran – Independent.
Height of students Weight of students Subject marks of students.
Perform Descriptive Statistics Section 6. Descriptive Statistics Descriptive statistics describe the status of variables. How you describe the status.
Getting Superscripts into your SAS output Martha Cox Population Health Research Unit Community Health & Epidemiology Dalhousie University.
Section 3.2C. The regression line can be found using the calculator Put the data in L1 and L2. Press Stat – Calc - #8 (or 4) - enter To get the correlation.
Toronto Area SAS Society December 8, 2006 How One Can Use SAS to Easily Manage an Otherwise Unmanageable Task Dr. Arthur S. Tabachneck Insurance Bureau.
The Power of the BY Statement SVSUG Paul Choate, California Developmental Services (& Toby Dunn, U.S. Army Medical Department Center & School)
Summer SAS Workshop Lecture 3. Summer SAS Workshop Website
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.
TASS Meeting Setting GuessingRows when Importing Excel Files September 19th, 2008 Setting GuessingRows when importing Excel Files Dr. Arthur Tabachneck,
Efficient SAS programming with Large Data Aidan McDermott Computing Group, March 2007.
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.
The number which appears most often in a set of numbers. Example: in {6, 3, 9, 6, 6, 5, 9, 3} the Mode is 6 (it occurs most often). Mode : The middle number.
BMTRY 789 Lecture 6: Proc Sort, Random Number Generators, and Do Loops Readings – Chapters 5 & 6 Lab Problem - Brain Teaser Homework Due – HW 2 Homework.
Use the SET statement to: –create an exact copy of a SAS dataset –modify an existing SAS dataset by creating new variables, subsetting (using a subsetting.
Second Period: PROC TABULATE Jill Casey. Example 1: Simple 2D Table.
TASS Meeting using inputn to re-format data September 25 th, 2009 using inputn to re-format data Dr. Arthur Tabachneck Director, Data Management Note:
1 Ready To Become Really Productive Using PROC SQL? Sunil Gupta Gupta Programming.
Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables.
TASS Meeting Quickly Finding Project Code March 13th, 2009 A way to quickly find all of your project code Dr. Arthur Tabachneck Director, Data Management.
Cell Diameters and Normal Distribution. Frequency Distributions a frequency distribution is an arrangement of the values that one or more variables take.
AP Biology: Standard Deviation and Standard Error of the Mean
Chapter 11 Reading SAS Data
z-Scores, the Normal Curve, & Standard Error of the Mean
Multiplication table. x
Two Way ANOVAs Factorial Designs.
آشنايی با اصول و پايه های يک آزمايش
AP Biology: Standard Deviation and Standard Error of the Mean
Bring the Vampire out of the Shadows: Understanding the RETAIN and COUNT functions in SAS® Steve Black.
Dr. Arthur Tabachneck Director, Data Management
Repetition (While Loop) LAB 9
a useful SAS 9.2 feature I wasn’t aware of *
Table 2. Showing mean and SD along with t- critical ratio
REPETITION Why Repetition?
© The Author(s) Published by Science and Education Publishing.
Twice daily regimen N=45 MDI regimen N=28 P Value
Presentation transcript:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Using Multiple DOW Loops Dr. Arthur Tabachneck Director, Data Management Idea stolen from a SAS Global Forum paper by Paul Dorfman and Koen Vyverman

TASS Meeting Using Multiple DOW Loops September 25th, 2009 suppose you had the following data: i.e., proc sort data=sashelp.class out=have; by sex; run;

TASS Meeting Using Multiple DOW Loops September 25th, 2009 and you needed to have the following table: i.e, with a new variable that shows height in terms of number of standard deviations from the group average separately, for males and females: (height-average)/sd Note: this presentation is about the method.. not the particular calculation. Of course, for some calculations, certain procs might be more advantageous

TASS Meeting Using Multiple DOW Loops September 25th, 2009 did you know you can do it in a single data step? data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run;

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Why it works: Look under the hood: Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run;

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Why it works: Under the hood-Loop #1: Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Alice F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run;

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Barbara F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #1:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Carol F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #1:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Jane F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #1:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Janet F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #1:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Joyce F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #1:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Judy F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #1:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Louise F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #1:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 1 Mary F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #1:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 1 Mary F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #1:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Alice F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #2:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Barbara F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #2:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Carol F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #2:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Jane F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #2:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Janet F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #2:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Joyce F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #2:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Judy F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #2:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Louise F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #2:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 1 Mary F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #2:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 1 Mary F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #2:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Alice F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #3:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Barbara F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #3:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Carol F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #3:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Jane F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #3:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Janet F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #3:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Judy F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #3:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Louise F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #3:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 1 Mary F PDV put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run; Why it works: Under the hood-Loop #3:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 1 Mary F PDV Why it works: Under the hood-2 nd Iteration-Loop #1: put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run;

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Last.sex Name Sex Age Height Weight First.Sex avg n sd z _ERROR_ _N_ 0 Alfred M PDV Why it works: Under the hood-2 nd Iteration-Loop #1: put _all_; data want (drop=n); do until(last.sex); set have; by sex; avg=sum(avg,height); n=sum(n,height/height); end; avg=avg/n; do until(last.sex); set have; by sex; sd=sum(sd,(height-avg)**2); end; sd=sqrt(sd/(n-1)); do until(last.sex); set have; by sex; if missing(height) then call missing(z); else z=(height-avg)/sd; output; end; run;

TASS Meeting Using Multiple DOW Loops September 25th, 2009 and, after completing all iterations, of course:

TASS Meeting Using Multiple DOW Loops September 25th, 2009 Questions? Your comments and questions are valued and encouraged. Contact the author: Dr. Arthur Tabachneck Director, Data Management Insurance Bureau of Canada Toronto, Ontario L3T 5K9