Hi, we need to filter a dataset (dsin). Grouping by each ID, we need to select by session the lowest grade. In cases when there is the same session value and same grade, the session that happened last (the highest numbered month)should be chosen (see dsout). data dsin,
input id session month grade;
datalines;
1 2 3 4
1 3 4 1
1 4 5 1
2 1 1 4
2 3 3 1
2 3 5 3
2 4 6 3
3 1 2 1
3 1 4 1
3 2 6 1
3 3 10 4
3 4 12 2
;
run;
data dsout,
input id session month grade;
datalines;
1 2 3 4
1 3 4 1
1 4 5 1
2 1 1 4
2 3 3 1
2 4 6 3
3 1 4 1
3 2 6 1
3 3 10 4
3 4 12 2
;
run; I tried this code but it is not filtering correctly: proc sort data=dsin;
by id session grade descending month;
run;
data dsout;
set dsin;
by id session grade;
if first.grade;
run; I am not sure what I am missing. Any advice is appreciated. Thanks!
... View more