x cd /pub/data/acspums/Tools; %let pgm=application_famswithpreschoolers; filename pgm "&pgm..sas" ; *---the request from DESE, June, 2011 Wanted a count and portion of Missouri families with own kids aged 0-2 and 3-5 for 2 most recent years. ----; libname acspums '/pub/data/acspums' access=readonly; %let year=2008; %let yr=08; %macro doit(year); %let yr=%substr(&year,3,2); data tocount; merge acspums.mohrecs&yr(keep=serialno wgtp HHT HUPARC where=(HHT in ('1','2','3')) in=inhrecs) acspums.moprecs&yr(keep=serialno agep rel agep where=('02'<=rel<='07') in=inprecs) end=lastobs; by serialno; if inhrecs; *<---filters to keep data only for hhs that are family hhs and persons in those hhs--; Families=1; if first.serialno then do; Kids0_to_2=0; Kids3_to_5=0; retain Kids: ; end; if inprecs and agep < 6 then do; if agep le 2 then Kids0_to_2=1; else if agep le 5 then Kids3_to_5=1; end; if last.serialno then do; retain Year "&year"; if Kids0_to_2 and Kids3_to_5 then KidsBothAges=1; else KidsBothAges=0; TotalFamilies+ wgtp; FamiliesWithKids0_to_2 + Kids0_to_2*wgtp; FamiliesWithKids3_to_5 + Kids3_to_5*wgtp; FamiliesWithKidsBothAges + KidsBothAges*wgtp; format TotalFamilies--FamiliesWithKidsBothAges comma12.; if lastobs then put _all_; end; run; %mend doit; %doit(2008); %doit(2009);