:smileylaugh: fair. Here is some really poorly written code, but it should give you an idea: *using sashelp.class as example; proc sql; select age, weight,height,sex, count(*) as count from sashelp.class where age is not null group by sex,age; quit; It gives the following output: Age Weight Height Sex count ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 11 50.5 51.3 F 1 12 84.5 59.8 F 2 12 77 56.3 F 2 13 98 65.3 F 2 13 84 56.5 F 2 14 102.5 62.8 F 2 14 90 64.3 F 2 15 112 66.5 F 2 15 112.5 62.5 F 2 11 85 57.5 M 1 12 83 57.3 M 3 12 99.5 59 M 3 12 128 64.8 M 3 13 84 62.5 M 1 14 112.5 69 M 2 14 102.5 63.5 M 2 15 112 66.5 M 2 15 133 67 M 2 16 150 72 M 1 Now, let's PROC it: First sort by what you are "group by" in your SQL: proc sort data = sashelp.class out = have; by sex age;run; *Create a temp file, so we don't sort the original; Then we use "where" and "keep" statements in the "set" statement: data want(keep = sex age cnt); set temp(where = (age ne 0) keep = age weight sex height); by sex age; if first.age then cnt = 1; else cnt ++ 1; if last.age; *we want the "total" count; run; Finally get it all together; data really_want; merge have want; by sex age; run; Hee,hee...
... View more