BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input patient_id week condition @@;
datalines;
1 1 0 
1 2 1 
1 3 3 
2 2 2 
2 5 1 
3 1 3 
4 2 0 
4 3 1 
4 4 1 
4 5 2 
;
run;

data want(drop = flag);
   set have;
   by patient_id;
   if first.patient_id then flag = 0;
   if flag = 0 then output;
   if condition = 1 then flag = 1;
   retain flag;
run;

 

Result:

 

patient_id week condition
1          1    0
1          2    1
2          2    2
2          5    1
3          1    3
4          2    0
4          3    1

 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input patient_id week condition @@;
datalines;
1 1 0 
1 2 1 
1 3 3 
2 2 2 
2 5 1 
3 1 3 
4 2 0 
4 3 1 
4 4 1 
4 5 2 
;
run;

data want(drop = flag);
   set have;
   by patient_id;
   if first.patient_id then flag = 0;
   if flag = 0 then output;
   if condition = 1 then flag = 1;
   retain flag;
run;

 

Result:

 

patient_id week condition
1          1    0
1          2    1
2          2    2
2          5    1
3          1    3
4          2    0
4          3    1

 

Quentin
Super User

Nothing is easy. : )

 

Can you show the code you have tried?  Did it involve RETAIN?  That will help others help you.

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 428 views
  • 1 like
  • 3 in conversation