不知道理解正确不?
data a;
input class @@;
cards;
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4
;
run;
data b;
set a;
set sashelp.class;
run;
proc sort data=b;
by class sex age;
run;
data b;
set b;
by class sex age;
if not( first.age=1 and last.age=1);
run;
data temp;
input id $ class sex $ age case_flg;
cards;
001 1 F 14 0
002 1 M 15 0
003 1 F 14 1
004 1 F 13 0
005 1 M 15 1
006 1 M 15 0
007 1 F 14 0
008 1 M 16 0
009 1 M 16 0
010 1 F 14 0
011 2 M 15 1
012 2 M 15 0
013 2 F 14 0
014 2 F 13 0
015 2 M 15 0
016 2 M 15 0
017 2 F 14 0
018 2 M 14 0
019 2 M 15 0
;
proc sql;
create table aim as
select *,ranuni(0) as random
from temp
where catx("_",class,sex,age) in
(select distinct catx("_",class, sex,age)
from temp
where case_flg=1)
group by class,sex,age,case_flg
having random=max(random)
order by class,sex,age,case_flg;
quit;