CSULB_STAT475_handout18

# CSULB_STAT475_handou - STAT 475 Chapter 12 READING SAS DATA SETS FINDING FIRST AND LAST OBSERVATIONS IN SUBGROUPS • FIRST variable is set to 1 at

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: STAT 475 Chapter 12 READING SAS DATA SETS FINDING FIRST AND LAST OBSERVATIONS IN SUBGROUPS • FIRST . variable is set to 1 at the first occurrence of a new value for a sorted variable ; otherwise, it is set to 0. • LAST . variable is set to 1 at the last occurrence of a new value for a sorted variable ; otherwise, it is set to 0. • Note that both FIRST.variable and LAST.variable are temporary variables that are not stored in the new data set. Example. In the exercise example, the following program calculates total payments due for men and for women. proc sort data=exercise; /* data set has to be sorted */ by Sex; run; data exercise; set exercise; by Sex; /* defines subgroups */ if first.Sex=1 then Total_Payment=0; Total_Payment+Payment; if last.Sex=1; /* selects only last observation in each Sex category */ run; proc print noobs; run; The output is Act Total_ ID Age Level Sex Payment Payment 2833 32 MOD F 15.5 78.50 2823 29 HIGH M 23.0 70.75 Underneath the surface SAS computes the following: 1 ID Age ActLevel Se x Payme nt First.S ex Last.S ex Total_Payment 2810 61 MOD F 34 1 0+34=34 2804 38 HIGH F 29 34+29=63 2833 32 MOD F 15.5 1 63+15.50=78.50 2807 42 LOW M 27.5 1 0+27.50=27.50 2816 26 HIGH M 20.25 27.50+20.25=47....
View Full Document

## This note was uploaded on 12/14/2011 for the course STAT 475 taught by Professor Olgak during the Fall '11 term at CSU Long Beach.

### Page1 / 6

CSULB_STAT475_handou - STAT 475 Chapter 12 READING SAS DATA SETS FINDING FIRST AND LAST OBSERVATIONS IN SUBGROUPS • FIRST variable is set to 1 at

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online