I nedd to write a PROC FORMAT
and PROC FCMP
in my SAS programm to convert values in horsepower to watts. Watts should have the following format: XXXXX,XX Watt.
proc fcmp outlib=work.functions.fun;
function hptow(c) $;
n = cats(c*745.7, ' Watts');
return (n);
endsub;
run;
options cmplib=work.functions;
proc format;
value hptow other=[hptow()];
run;
data my_cars;
set sashelp.cars;
format horsepower hptow.;
run;
But results look something like that:
197610.
201339W
How do i change this mistake and have needed output format for formated column?
Set a LENGTH for the variable you are calculating in the function. If you want the space in front of the W then don't remove it by using the CATS() function.
Set a default width for the format.
But why not just use a PICTURE format?
Results: