BookmarkSubscribeRSS Feed
Astounding
PROC Star

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.

4 REPLIES 4
rams
Calcite | Level 5

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

Astounding
PROC Star

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.

art297
Opal | Level 21

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

Astounding
PROC Star

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 880 views
  • 0 likes
  • 3 in conversation