//* Brief Description: Generic macro that creates a heme iron analysis file. Calculates each subject's heme iron intake from a file containing subject id, meatid, weekly frequency of consumption, gram amount or portion size(S,M,L), and optionally gender and age. If portion size is S, M, or L instead of a number then the appropriate portion size from the heme iron txd file is used(based on gender and age, if both are non-missing). Add this macro to your program using the %include statement. The macro takes three parameters: 1) Fileref for meat frequency/serving size file 2) Fileref for heme iron database 3) Name of the dataset which will contain the heme iron values for each subject when the macro finishes. //* Additional Description: //* End Description: */ %macro hemeiron(freqgram,database,hemedata); proc format; value $portion 'S' = '1' 'M' = '2' 'L' = '3'; value $gender 'F' = '1' 'M' = '2'; value age 1 - <30 = '1' 30 - <70 = '2' 70 - HIGH = '3'; data &hemedata; length description $ 42; infile &database lrecl=160 pad; input @1 link 3. @6 description $42. @48 redwhite $1. @50 heme_iron_amount 10. @70 standard_small 4. @74 standard_medium 4. @78 standard_large 4. @82 young_female_small 4. @86 young_female_medium 4. @90 young_female_large 4. @94 young_male_small 4. @98 young_male_medium 4. @102 young_male_large 4. @106 middle_female_small 4. @110 middle_female_medium 4. @114 middle_female_large 4. @118 middle_male_small 4. @122 middle_male_medium 4. @126 middle_male_large 4. @130 old_female_small 4. @134 old_female_medium 4. @138 old_female_large 4. @142 old_male_small 4. @146 old_male_medium 4. @150 old_male_large 4.; data &freqgram; length id portion_size $ 8; length gender $ 1; infile &freqgram dsd lrecl=100 pad missover; input id $ link weekfreq portion_size $ gender $ age; if id = '' or link = . or weekfreq = . or portion_size = '' then put 'ERROR: Missing Data ' id= link= weekfreq= portion_size=; proc sort data=&hemedata; by link; proc sort data=&freqgram; by link; data &hemedata; merge &freqgram(in=infg) &hemedata(in=inh); by link; if infg and (not inh) then put 'ERROR: Meat Link not in heme iron file' link=; else if infg then output &hemedata; proc sort data=&hemedata; by id; data &hemedata(keep=id heme_iron rheme_iron wheme_iron); retain heme_iron rheme_iron wheme_iron; set &hemedata; by id; array standard(3) standard_small standard_medium standard_large; array genderage(3,2,3) young_female_small young_female_medium young_female_large young_male_small young_male_medium young_male_large middle_female_small middle_female_medium middle_female_large middle_male_small middle_male_medium middle_male_large old_female_small old_female_medium old_female_large old_male_small old_male_medium old_male_large; if first.id then do; heme_iron = 0; rheme_iron = 0; wheme_iron = 0; end; if translate(portion_size,'###########','1234567890.') in ('#','##','###','####','#####','######','#######','########') then tempheme = weekfreq * input(portion_size,8.) * heme_iron_amount / 7; else if gender = '' and age = . and upcase(portion_size) in ('S','M','L') then tempheme = weekfreq * standard(input(put(upcase(portion_size),$portion.),1.)) * heme_iron_amount / 7; else if upcase(gender) in ('M','F') and age >= 1 and upcase(portion_size) in ('S','M','L') then tempheme = weekfreq * genderage(input(put(age,age.),1.), input(put(upcase(gender),$gender.),1.), input(put(upcase(portion_size),$portion.),1.)) * heme_iron_amount / 7; else do; tempheme = 0; put 'ERROR: ' portion_size= gender= age=; end; if tempheme ne 0 then do; heme_iron = heme_iron + tempheme; if upcase(redwhite) = 'R' then rheme_iron = rheme_iron + tempheme; else if upcase(redwhite) = 'W' then wheme_iron = wheme_iron + tempheme; else put 'ERROR: ' redwhite=; end; if last.id then do; heme_iron = round(heme_iron,.01); rheme_iron = round(rheme_iron,.01); wheme_iron = round(wheme_iron,.01); output; end; label id = 'subject ID' heme_iron = 'heme iron from meat (bhnrc) (mcg/day)' rheme_iron = 'heme iron from red meat (bhnrc) (mcg/day)' wheme_iron = 'heme iron from white meat (bhnrc) (mcg/day)' ; %mend hemeiron;