Hi all. I’m reasonably new to base SAS and SQL and I am trying to learn how to simplify the programs I write. I would like to try and condense the program below down into fewer steps with both a proc SQL and base SAS version. Basically the program below identifies cases which contain individuals that are 21 and older in the case. I am looking to delete from the final data set all the cases which contain only one case and that age of that person in greater than 21 BUT if the case contains more than one individual and all the individuals’ age is greater than or equal 21 that case is deleted also. This is what I’m trying to do: case_no age S6034840 21 Delete Case S5439846 22 Delete Case S5324014 17 Keep Case S5324014 21 S5324014 22 S5324014 13 S5286132 21 Delete Case S5270236 22 Delete Case S5268581 18 Keep Case S5268581 14 S5268581 14 S5232142 17 Keep Case S5232142 13 S5171614 21 Delete Case S5034350 18 Keep Case S5028771 17 Keep Case S5028771 18 S5023333 21 Delete Case S5023333 22 1. This first step brings in DOB (date of birth) into a previously created dataset and then calculates the age at the time on a certain data (DTDUE). proc sql; create table want as select a.* , b.DOB, %age(DTDUE,dob)as age from have1 A LEFT JOIN have2 B on a.id=b.id order by case_no; quit; 2. This step just pulls all the observations where the age is greater or equal to 21. data GE_21; set agytable; where age ge 21;run; 3. Then is step goes back to the want dataset and pulls all the cases which have individuals that are 21 or older in them. proc sql; create table GE_21_cases as select a.* from want a where CaseNo in (select CaseNo from GE_21) order by CaseNo, age desc; quit; 4. This step deletes cases where there is only one person in the case and that person’s age is greater than or equal two 21. data GE_21_cases; set Ge_21_cases ; by caseno; if first.caseno; if last.caseno; run; 5.This step goes back the original data set and deletes the cases. Proc sql; create table want as select * from want a where CaseNo not in (select CaseNo from GE_21_cases); quit; Again, I would like to try and condense the program below down into fewer steps with both a proc SQL and base SAS version. And if there is anything I’m missing your advice is appreciated with that also. Thanks!!
... View more