DATA Step, Macro, Functions and more

Re: how to get the consecutive elevations flagged

Reply
Super User
Posts: 5,503

Re: how to get the consecutive elevations flagged

Any easy solution will need to make two passes through the data.  If two passes through the data is not practical, we can always revisit.  So assuming that your data is already in sorted order, and assuming that you followed the suggested solution to create FLAG, process again:

data want;

   set want;

   by subject test flag notsorted;

   if flag=1 and (first.flag=0 or last,.flag=0) then elevated_consecutive_flag='*';

run;

Optionally, you could drop FLAG at that point as well.

New Contributor
Posts: 3

Re: how to get the consecutive elevations flagged

Posted in reply to Astounding

Hii

i have a dataset like this

subjecttestvisithigh_rangeactual_value
101A130100
101A23090
101A33080
101A43060
101A53055
101A63065
101A73070
101A83095
101B140130
101B240150
101B34065
101B44085
101B540120
101B640135

and i want to flag the >= 3 time elevated values into one variable

then i want to flag the consecutive flags into another variable like this and that to by subject and test

output like this

subjecttestvisithigh_rangeactual_valueflag_>=3t_elevconsec_flags
101A130100yy
101A23090yy
101A33080nn
101A43060nn
101A53055nn
101A63065nn
101A73070nn
101A83095yn
101B140130yy
101B240150yy
101B34065nn
101B44085nn
101B540120yy
101B640135yy

can you please help me out.

Thanks

Super User
Posts: 5,503

Re: how to get the consecutive elevations flagged

OK, putting together all the previous suggestions, and taking the simplest route:

proc sort data=have;

by subject test visit;

run;

data want;

set have;

if actual_value >= 3*high_range then flag_3xElev='y';

else flag_3xElev='n';

run;

data want;

set want;

by subject test flag_3xElev notsorted;

if flag3xElev='y' and (first.flag_3xElev=0 or last.flag_3xElev=0) then consec_flags='y';

else consec_flags='n';

run;

Good luck.

PROC Star
Posts: 7,471

Re: how to get the consecutive elevations flagged

Posted in reply to Astounding

: Just out of curiosity, why was this branched to a separate discussion AND how was that accomplished?

Super User
Posts: 5,503

Re: how to get the consecutive elevations flagged

Art,

I don't know ... I didn't do anything to make it happen.  Funny thing is, it now appears in my Content section even though I didn't really initiate it.

All questions and no answers on that one.

Ask a Question
Discussion stats
  • 4 replies
  • 259 views
  • 0 likes
  • 3 in conversation