when I use put statement to convert a numeric variable to character one, using the following code will make missings to '.', not blank.
VSSTRESC=strip(put(VSRESPORRES,best.));
Then I need to use the following code to avoid '.'
if VSRESPORRES ne . then VSSTRESC=strip(put(VSRESPORRES,best.));
else VSSTRESC='';
I have many such variables to convert. I wonder if there is an easier way to avoid it?
If you're lazy, you can use CATT, it does an automatic conversion, with no message in the log.
option missing='';
data class;
set sashelp.class;
if age=13 then
weight=.;
run;
data check;
set class;
test1=catt(weight);
test2=put(weight, best.);
run;
title 'Missing with space';
proc print data=check (obs=5);
run;
option missing=.;
title 'Missing with period';
proc print data=check(obs=5);
run;
add options missing=' '; before your step
Thank you. Will this option statement affect the missing values of numeric varaibles in the same data step?
the option options missing=' '; affects only how it is displayed.
As an alternative to the missing option which affects how missings are printed for all numerical variables, you can also define your own format as demontrated in the code below.
Also: To get your result left aligned you could use syntax <format name>.-L
proc format;
value MyBest(default=16)
low-high=[best.]
other=' ';
run;
data sample;
VSRESPORRES=1;
VSSTRESC=put(VSRESPORRES,MyBest.-L);
output;
VSRESPORRES=.;
VSSTRESC=put(VSRESPORRES,MyBest.-L);
output;
run;
If you're lazy, you can use CATT, it does an automatic conversion, with no message in the log.
option missing='';
data class;
set sashelp.class;
if age=13 then
weight=.;
run;
data check;
set class;
test1=catt(weight);
test2=put(weight, best.);
run;
title 'Missing with space';
proc print data=check (obs=5);
run;
option missing=.;
title 'Missing with period';
proc print data=check(obs=5);
run;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.