x cd /pub/data/acspums/Tools; %let pgm=state_views; filename pgm "&pgm..sas"; *---Add state indices to the ushrecs and usprecs datasets for latest year (&year) and define views that access the p and h recs for each state. jgb, 8-31-06. 9-24-07 to do it for the 2006 data. ---*; %let year=2006; %let yr=%substr(&year,3,2); title "&pgm.: Create Views Referencing ushrecs and usprecs for Each State"; libname acspums '/pub/data/acspums'; /* =======================Begin comment================ (already ran) *----test sort order for merge-ability of mo datasets----; data test(keep=st serialno _case); merge acspums.mohrecs&yr(in=inh) acspums.moprecs&yr(in=inp); by serialno; if inh and inp then _case='b'; else if inh then _case='h'; else _case='p'; run; proc freq data=test; table _case; run; proc datasets library=acspums nolist; modify ushrecs&yr; index create st; modify usprecs&yr; index create st; quit; ======================End comment================== */ options ps=55 ls=80 nodate; %macro doit(state,stab); data acspums.&stab.hrecs&yr(label="H records for &statenm, &year")/view=acspums.&stab.hrecs&yr; set acspums.ushrecs&yr; where st="&state"; run; data acspums.&stab.precs&yr(label="P records for &statenm, &year")/view=acspums.&stab.precs&yr; set acspums.usprecs&yr; where st="&state"; run; proc freq data=acspums.&stab.hrecs&yr(keep=st puma); by st; table puma / nopercent; format st $state.; run; %mend doit; options mprint; *---We invoke the doit macro for all states except 29/mo. Missouri has actual sas datasets with the same names, hence we cannot create views. Note inclusion of 72/pr ---; %dostates(01 02 04 05 06 08 09 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28,names=1); %dostates(30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 53 54 55 56 72,names=1)