You can't change the type of an existing SAS variable, you have to create a new variable based on the old one. One common trick is to rename the variable you want to switch like below, then recreate the original variable:
proc format;
value yn
0='N'
1='Y';
run;
data want;
drop tmp_:;
set have (rename = (MyYesNoVar = tmp_MyYesNoVar));
MyYesNoVar = put(tmp_MyYesNoVar, yn.);
run;
@nickspencer - Yes. An array in the example code I posted could do this. How many variables do you want to change?
This will convert all 0/1 to n/y. Many variables. And preserve variable order as specified in VAR statement.
data ind;
length ind_name ind_adr ind_sal 8.;
array _ind[*] ind_:;
do subject=1 to 10;
do i = 1 to dim(_ind);
_ind[i] = ranbin(1234,1,.5);
end;
output;
end;
drop i;
attrib ind_: label='Label to preserve';
run;
proc format; value yn 1='Y' 0='N';
proc transpose data=ind out=flip;
by subject;
var ind_:;
format ind_: yn.;
run;
proc print;
run;
proc transpose data=yn out=ind2(drop=_name_);
by subject;
var yn;
id _name_;
idlabel _label_;
run;
proc print;
run;
proc contents varnum;
run;
Here is the start of a solution. It could be improved by dynamically creating a RENAME = list using SAS DICTIONARY tables.
data want;
drop tmp_:;
array indicators (*) ind_V1 ind_V2;
array tmp_indicators (*) tmp_ind_V1 tmp_ind_V2;
set have (rename = (ind_V1 = tmp_ind_V1 ind_V2 = tmp_ind_V2));
do i = 1 to dim(indicators);
indicators(i) = put(tmp_indicators(i), yn.);
end;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.