Hello Can someone help me in tacking the below and assigning them the flag. Below is are unique records, I want to flag and increment if they fall under same visit and id, and reflag if not same visit id date visit output 1 2001-02-21 3 --------------->flag =1 1 2001-02-22 3 --------------->flag =2 2 2002-02-26 9 --------------->flag =1 3 2002-12-13 2 --------------->flag =1 3 2002-12-29 9 --------------->flag =1 4 2004-12-13 7 ---------------->flag =1 4 2004-12-14 7 ----------------->flag =2 4 2005-01-06 24 ------------------>flag =1 4 2005-01-07 24 ------------------>flag =2 For above: data test; infile datalines dsd; input id 1-2 date $3-12 visit 14 ; datalines; 1 2001-02-21 3 1 2001-02-22 3 2 2002-02-26 9 3 2002-12-13 2 3 2002-12-29 9 4 2004-12-13 7 4 2004-12-14 7 4 2005-01-06 24 4 2005-01-07 24 ; run; Criteria here a)for first record same id, visit assign flag=1, when the visit is same for the same id, but the date change than increase the flag by 1. b) when the first id and and second id observation is same, the visit is different and they are the first record for the the id assign flag to 1. 3) over all id falls in the same visit but changes can be seen on the data increment
... View more