Reputation: 4132
I am parameterising some code by having case when statements as macro variables that are then later injected into another macro. I therefore need to convert the strings into global variables, but am struggling to get everything masked. A simplified version of my code looks like so:
%macro test();
%let x_var =
case when var = 'Red' then 1
when var = 'Black***' then 2
when var = 'Deep Purple' then 3
else 4
end as var_sort
;
%global var = %nrbquote(&x_reg.);
%mend;
%test;
...however, that is failing to mask everything as I am receiving log errors of the order:
ERROR: Invalid symbolic variable name =.
ERROR: Invalid symbolic variable name =.
ERROR: Invalid symbolic variable name '.
ERROR: Invalid symbolic variable name '.
ERROR: Invalid symbolic variable name 1.
Can anyone advise on a fix, please? I always get confused a bit when trying to mask special characters as to which is the correct method to use.
Thanks
Upvotes: 0
Views: 1914
Reputation: 51611
The %global
statement is used to define a macro variable (symbol). If you want to assign it a value then use a %let
statement.
%global var ;
%let var = %nrbquote(&x_reg.);
If you want to set var
to literally &_rx_reg.
then use a data step.
data _null_;
call symputx('var','&x_reg.','g');
run;
Upvotes: 3