BookmarkSubscribeRSS Feed
avama
Calcite | Level 5

I am trying to create the rules. For example, we always start at HIGH cases --> if there are two values in a row by each group were the it falls between 11 through 20, i would like to assign it High regardless of the whether those two high values are in the top, middle, or or bottom for that group. If they are not High, then we see if there are two consequective values that are between 1 through 10 and assign them "LOW"

 

I have two legends - High (11 through 20) and Low (1 through 10)

 

Here's the sample dataset:

GROUPVALUEseq_id
1121
142
163
154
1135
4121
4132
413
424
5191
522
533
5144
5205

 

 

Here's the output:

IDvalueseq_idoutput
1121 
142Low
163 
154 
1135 
4121High
4132 
413 
424 
5191 
522 
533 
5144High
5205 
2 REPLIES 2
TomKari
Onyx | Level 15

In group 1, the value for seq_id 1 is 12 and for seq_id 5 is 13, so shouldn't output for group 1 be HIGH?

ChrisNZ
Tourmaline | Level 20

Not too sure which row you want the OUTPUT value on. Just merge back as wanted.

This works:

data WANT;
  set HAVE;
  length OUTPUT $8;
  retain OUTPUT;
  by  GROUP;
  if first.GROUP then OUTPUT=' ';
  if lag(GROUP)=GROUP and lag(VALUE)>10 and VALUE>10 then OUTPUT='High';
  if lag(GROUP)=GROUP and lag(VALUE)<=10 and VALUE<=10 and OUTPUT= ' ' then OUTPUT='Low';
  if last.GROUP then output;
  keep GROUP OUTPUT;
run;
GROUP OUTPUT
1 Low
4 High
5 High

 

 

 

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
  • 2 replies
  • 879 views
  • 0 likes
  • 3 in conversation