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

We are analyzing data in the following format.   Our question is,

how can we identify IDs where the difference between any 2 sequential values for "Level" is more than 2?

We have looked through SAS resources and, as relatively new programmers, can't figure this out.

 

Thank you!!

 

ID  Date                   Level  

1    01/01/2000        1

1    01/02/2000        

1    01/05/2000        3

1    01/05/2010

2    01/06/2010        5

2    02/12/2005        6

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Did you mean greater than or equal to 2? That's an easy tweak to the logic if necessary.

Here's a way to identify all observations that increased by 2 or more:

data want;
set have;
by id;
where level > .;
if dif(level) > 1;
if first.id = 0 ;
run;

So there's still some work to do, but this gets you through the hard part. Make me proud and take it home the rest of the way.

View solution in original post

4 REPLIES 4
Reeza
Super User

How do you want to deal with cases where you're missing values between sequential values as in your data? Show your expected output please. 

 

In general, you likely want the DIF function but it's a bit tricky to use if you're not familiar with SAS. 

 

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n10t6w4op574ttn11yk68dottp7f.htm...

 


@anissak1 wrote:

We are analyzing data in the following format.   Our question is,

how can we identify IDs where the difference between any 2 sequential values for "Level" is more than 2?

We have looked through SAS resources and, as relatively new programmers, can't figure this out.

 

Thank you!!

 

ID  Date                   Level  

1    01/01/2000        1

1    01/02/2000        

1    01/05/2000        3

1    01/05/2010

2    01/06/2010        5

2    02/12/2005        6

 

 

 


 

anissak1
Obsidian | Level 7

Thank you for the note!  We would like to ignore the observations for which we have no value.

Astounding
PROC Star
Did you mean greater than or equal to 2? That's an easy tweak to the logic if necessary.

Here's a way to identify all observations that increased by 2 or more:

data want;
set have;
by id;
where level > .;
if dif(level) > 1;
if first.id = 0 ;
run;

So there's still some work to do, but this gets you through the hard part. Make me proud and take it home the rest of the way.
anissak1
Obsidian | Level 7
Thank you!! I guess you are a master for a reason. 😊. Much appreciation. We are close to crossing the finish line

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1018 views
  • 2 likes
  • 3 in conversation