You'd need to write a function style macro if you were to do what you're doing above, which isn't really easy to do (possible, but not sufficiently easy to be worth doing).
Macros aren't functions by nature, they're just code that you write elsewhere and repeat. So you can't really call a macro on the right-hand side of the equal sign unless the only non-macro code it includes is code valid on the right hand side of an equal sign.
In this case, I agree with format
as the solution. You need to use the cntlin
option in proc format
, and you would need to create the format before you run the data step.
You need fmtname
, start
, label
at minimum. type
is also commonly included. hlo="o"
row is also a good idea (for "other").
data for_fmt;
set parametric_table;
retain fmtname 'PARAMETF' type 'N'; *or 'C' and include a $ if character;
rename
original_Value = start
transformed_value = label
;
output;
if _n_=1 then do;
hlo='o';
call missing(original_value);
transformed_value = .; *or ' ' or whatever you want a non-match to return;
output;
end;
run;
proc format cntlin=for_fmt;
quit;
Make sure that you don't have duplicate start
values, but otherwise this is your best approach for what you're describing. Then you have
data transformation;
set transformation;
new_value = input(put(old_value,PARAMETF.),BEST12.); *or whatever depending on what you are doing. Format makes CHAR value always, so `input` to convert to number.;
run;
No need for macros here, though you certainly could (And, I'd say, should) have a generic macro for creating formats like this.