%macro raceidx(race_id,length=3,white=white,black=black,indian=indian,asian=asian,hawnpi=hawpi,other=other, nraces=nraces); %*--this macro will take a single numeric race id code as defined in our Census 2K PL94 conversion program and will assign values to 7 numeric variables, 6 race "flags" (1/0 values depending on whether the race_id value means that race is included) and the nraces var with the count of races specified. If the value of the variable whose name is passed is missing then all the flags are set to missing. Will also accept a 0 value and will assign all flags to 0. Use named parms to override the names (e.g. specify " black=bflag " to have the program assign 1 or 0 to the varaible bflag instead of the default variable black.) By default the varialbles are declared as being numeric of length 3. Specify a different numeric length of specify "length=0" to have macro not generate a length stmt. John Blodgett, MCDC, Feb. 2001. --*; /* -------------------Sample invocation-------------------------- data _null_; do race_id=1 to 63; put race_id= race_id binary6.; %raceidx put _all_; end; run; ------------------ */ %if %eval(&length) gt 2 and %eval(&length) le 8 %then %do; length &white &black &indian &asian &hawnpi &other &nraces &length; %end; %if %quote(&race_id) eq %str() %then %let race_id=race_id; if 1 le &race_id le 63 then do; &white= mod(&race_id,2)=1; *--set white flag to true (1) iff low order binary digit is 1; &black= mod(int(&race_id/2),2)=1; *--black flag based on the "2"s digit of the binary number-; &indian= mod(int(&race_id/4),2)=1; &asian= mod(int(&race_id/8),2)=1; &hawnpi= mod(int(&race_id/16),2)=1; &other= mod(int(&race_id/32),1)=1; &nraces=sum(of &white &black &indian &asian &hawnpi &other); end; else do; &white=.; &black=.; &indian=.; &asian=.; &hawnpi=.; &other=.; &nraces=.; end; %mend raceidx;