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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.