BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
wcw2
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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;

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

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;
wcw2
Obsidian | Level 7

Yes indeed. Thanks so very much!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Health and Life Sciences Learning

 

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.

LEARN MORE

Discussion stats
  • 2 replies
  • 958 views
  • 2 likes
  • 2 in conversation