I don't like using that many nested if-statements. In the past various flags were stored in a single numeric variable, to save memory. So, i translated the "Yes" to 1 and "No" to 0, concatenated the 1s and 0s and used a format to get the requested text. The data-step has been reduced to the creation of priorrx. proc format;
value priorrxFmt
1 = 'hormonal treatment'
2 = 'chemotherapy'
3 = 'chemotherapy+other treatment'
4 = 'radiotherapy'
5-7 = 'radiotherapy+other treatment'
8 = 'immunotherapy'
9-15 = 'immunotherapy+other treatment'
16 = 'Surgery'
17-31 = 'Surgery+other treatment'
other = 'none of listed treatments'
;
run;
data want;
length binaryString $ 5 priorrx $ 40;
set have;
array t surgery immunerx radiotherapy chemotherapy hormonal;
do i = 1 to dim(t);
binaryString = cats(binaryString, ifc(t{i} = 'Yes', '1', '0'));
end;
priorrx = put(input(binaryString, binary5.), priorrxFmt.);
drop binaryString;
run;
... View more