Ideally transpose your source data from a wide to a long data structure which is most of the time easier to work with.
There is no need to create a full set of additional string variables if it's just about printing/reporting. You could generate and use formats instead as done in below sample code.
data work.have;
input ID safe house food;
cards;
1 1 . .
2 . 1 1
3 . 1 .
4 1 . 1
;
run;
proc sql noprint;
select
catx(' ','value',name,"1='",name,"';"),
catx(' ',name,cats(name,'.'))
into
:fmt_def separated by ' ',
:fmt_apply separated by' '
from dictionary.columns
where libname='WORK' and memname='HAVE' and upcase(name) ne 'ID'
;
quit;
proc format;
&fmt_def;
run;
/*** proc dataset if you want to apply the formats permanently ***/
/*proc datasets lib=work nolist;*/
/* modify have;*/
/* format &fmt_apply;*/
/* run;*/
/*quit;*/
proc print data=have;
/* format statement here only required if formats not applied permanently */
format &fmt_apply;
run;
Please note that variables Safe, House and Food are still numeric and the internal values stored are still 1 or missing. The generated formats applied just change how the values get printed.
If you apply the formats permanently then you also need to store the compiled format definitions permanently or you need to re-create them whenever you want to use them.
... View more