For Q1, SQL plus intnx() mentioned by mojerry will make one of the solutions. data have; infile cards; input ChildID $10. ACT $ ACTDate :mmddyy8. AgencySpellBegin : mmddyy10. AgencySpellEnd : mmddyy10.; format ACTDate date9. AgencySpellBegin date9. AgencySpellEnd date9.; cards; Childid1 M999 11/30/11 9/12/01 12/12/2414 Childid1 M956 11/12/11 9/12/01 12/12/2414 Childid2 M990 7/12/11 7/12/02 2/12/2414 Childid3 M999 1/1/12 6/13/04 2/12/2414 Childid3 M900 11/11/11 6/13/04 2/12/2414 Childid3 M956 10/12/11 6/13/04 2/12/2414 Childid4 M956 1/1/11 8/9/04 1/12/12 Childid5 M450 9/12/11 7/12/05 2/12/2414 Childid6 M956 8/12/11 7/12/03 1/12/11 Childid7 M956 1/12/12 1/12/09 2/12/2414 ; /*Q1 , awols and returns*/ proc sql; create table awol as select distinct childid from have where act='M956' and actdate>=intnx('month',today(),-7,'sameday') ; create table return as select distinct childid from have where actdate>=intnx('month',today(),-7,'sameday') group by childid having sum(act='M956')>0 and sum(act='M999')>0 ; quit; Please note, if you want to define your month from the first day of every month, you need to remove 'sameday' option from intnx(). Q2 seems to be straighforward question, however, results could vary depend on what you want. Please refer a recent discussion on SAS-L. http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1201B&L=sas-l&P=R13704 Regards, Haikuo
... View more