I am using a macro in SAS to loop over the data tables in a specific library. I put the metadata information in a data null step and make a comparison with a where statement and my macro variable.
My SQL step looks like:
proc sql;
select quote(trim(code)) into :procedures separated by ', ' from procedures;
quit;
Some values of code
contain values like "45.10" and "G0102", so cannot be coerced to numeric. The macro contains the line:
%macro filter_codes(indata, outdata);
data &outdata;
set &indata(where = (code in (&procedures)));
run;
%mend;
but the decimal values create an issue when double-quoted using the "quote" function.
Can I separate values with single quotes?
EDIT: The issue was caused by the fact that the filter_codes macro was run within a call execute step (over a range of datasets) and double quotes resolved in macro variables inside of double quotes would end the call execute.
Try this:
Also fix the where option in set statement:
Fix the issue where you reference the variable. Sounds like you were trying to use something like
First there is no need to use double quotes in the CALL EXECUTE string. Push the &procedures onto the command stack unresolved.
If you did want to resolve the macro variable then look at using %sysfunc(quote()).
How about in one step using SQL?
No need to worry about quoting then.
In 9.3 you have a second argument, enabling you to use single quotes in the
quote()
function.However.. Am not a fan of this function as it pads empty character variables with a single space (see below).
Unfortunately it's the only 'in built' way (other than a proc export or suchlike) to get reliable quoting applied (eg quoting the quotes).