*================================================================================ / Program Name: sas0210.sas / / Author: Tom Cook / / Creation Date: February 4, 2005 / / Project: 642 / / Purpose: Appleton Data Example / / / *===============================================================================; options linesize = 80 nodate ; proc format ; value agefmt 1 = "18-24" 2 = "25-34" 3 = "35-44" 4 = "45-54" 5 = "55-64" 6 = "65-74" 7 = "75+" ; value ageraw 18-<25 = "18-24" 25-<35 = "25-34" 35-<45 = "35-44" 45-<55 = "45-54" 55-<65 = "55-64" 65-<75 = "65-74" 75-high = "75+" ; value agerawn 18-24 = "1" 25-34 = "2" 35-44 = "3" 45-54 = "4" 55-64 = "5" 65-74 = "6" 75-high = "7" ; value smokefmt 1 = "Smoker" 2 = "Non-Smoker" ; value deadfmt 1 = "Dead" 2 = "Alive" ; data apple_raw ; infile "apple.raw.dat" ; input age smoke dead ; age_grp1 = floor((age-5)/10) ; if age < 25 then age_grp2 = 1 ; else if age < 35 then age_grp2 = 2 ; else if age < 45 then age_grp2 = 3 ; else if age < 55 then age_grp2 = 4 ; else if age < 65 then age_grp2 = 5 ; else if age < 75 then age_grp2 = 6 ; else age_grp2 = 7 ; age_grp3 = put(age, ageraw.) ; age_grp4 = put(age, agerawn.) + 0 ; format age_grp1 age_grp2 age_grp4 agefmt. smoke smokefmt. dead deadfmt. ; run ; proc contents ; options obs = 10 ; title "Appleton data - Unformated" ; proc print ; format age_grp1 age_grp2 age_grp3 age_grp4 smoke dead ; run ; title "Appleton data - Formated" ; proc print ; run ; options obs = max ; proc sort data = apple_raw ; * sort in place ; by age_grp1 smoke dead ; run ; data apple_grouped ; set apple_raw ; by age_grp1 smoke dead ; drop age ; retain count ; if first.dead then count = 0 ; count + 1 ; if last.dead then output ; run ; title "Appleton data - Grouped" ; proc print ; run ; proc freq data = apple_raw ; ** use 'noprint' to suppress printing of tables; tables age_grp1*smoke*dead / out=apple_groupedF ; run ; title "Appleton data - Grouped using PROC FREQ" ; proc print data=apple_groupedF ; run ; title "Appleton data - Compute statistics using PROC FREQ" ; proc freq data = apple_grouped ; weight count ; tables age_grp1*smoke*dead / all cmh ; ** or / chisq measures ; run ;