How to upcase all character variables in a SAS dataset
To upcase all character variables in a SAS dataset, you can use a DATA
step with the UPCASE()
function in combination with the VARNUM()
and VARNAME()
functions to iterate through all variables. Here's an example:
data upcased_dataset;
set original_dataset;
array _char_vars _character_; /* Create an array of all character variables */
do i = 1 to dim(_char_vars);
_char_vars[i] = upcase(_char_vars[i]); /* Convert each variable to uppercase */
end;
drop i;
run;
Explanation:
array _char_vars _character_;
creates an array_char_vars
that includes all character variables in the dataset.- The
do i = 1 to dim(_char_vars);
loop iterates through each character variable in the array. _char_vars[i] = upcase(_char_vars[i]);
applies theUPCASE()
function to each character variable, converting it to uppercase.drop i;
removes the temporary index variablei
from the final dataset.
Replace original_dataset
with the name of your dataset, and upcased_dataset
will be the name of the new dataset with all character variables in uppercase.