Best is to know your data and define variables based on this knowledge (like a pre-defined data dictionary).
If I understand your question then below code for what you've been asking for.
data have;
input myvar $50.;
datalines;
white
American
black or white
;
proc sql noprint;
select max(lengthn(myvar)) into :myvar_max_len trimmed
from have
;
quit;
%put &=myvar_max_len;
data want;
length myvar $ &myvar_max_len;
set have(rename=(myvar=_myvar));
myvar=_myvar;
drop _myvar;
run;
proc contents data=want;
run;
If you just want to reduce the variable length to save storage space then consider using option compress=yes as this will compress blanks when storing a SAS table on disk.