I need to do a data check that will flag any numeric values that are not identical to others in a group, see below. The first GROUPNO value of each group will always be correct. Thanks.
OBS GROUPNO FLAG (want)
1 6
2 6
3 6
4 5 x
5 6
6 6
7 6
8 20
9 21 x
10 20
11 20
12 20
Hello @wcw2,
You'll need an additional variable (like variable grp in the example below) designating the groups or some other criterion to tell SAS where a new group begins.
data have;
input grp GROUPNO;
cards;
1 6
1 6
1 6
1 5
1 6
1 6
1 6
2 20
2 21
2 20
2 20
2 20
;
data want(drop=_g1);
set have;
by grp; /* add NOTSORTED option if needed */
if first.grp then _g1=groupno;
else if groupno ne _g1 then FLAG='x';
retain _g1;
run;
Hello @wcw2,
You'll need an additional variable (like variable grp in the example below) designating the groups or some other criterion to tell SAS where a new group begins.
data have;
input grp GROUPNO;
cards;
1 6
1 6
1 6
1 5
1 6
1 6
1 6
2 20
2 21
2 20
2 20
2 20
;
data want(drop=_g1);
set have;
by grp; /* add NOTSORTED option if needed */
if first.grp then _g1=groupno;
else if groupno ne _g1 then FLAG='x';
retain _g1;
run;
Yes indeed. Thanks so very much!
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →
Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.