Hello! I was wondering if someone could explain to me why my code isn't working correctly. I think it's something to do with how the SAS processor handles macro variables but I'm not entirely sure. data test;
input unformatted_var $;
DATALINES;
1
;
run;
%let format = not_a_format;
data test;
set test;
have_format = 0;
if have_format then do;
formatted_var = put(unformatted_var, &format.);
end; else do;
formatted_var = unformatted_var;
end;
run;
PROC PRINT DATA = test; run; The code is a simplified version of my main code which runs within a macro. It's purpose is to take unformatted_var and output it as formatted_var. Sometimes the code will have a format stored in the " format" macro variable in which case a format is applied to the formatted _var, other times there is no format supplied and the formatted_var is the same as unformatted_var. In the case above there is no format supplied so the have_format variable is set to 0. However despite this the code produces an error because it is trying to execute the line formatted_var = put(unformatted_var, &format.); Which can't run correctly because the "format" macro variable does not contain a format, even though that line should not be executed within the data step. I am able to solve my problem by coding it differently, but I'm not sure why it's not working in the first place! Thanks in advance.
... View more