简体   繁体   中英

How to create a SAS macro variable name from another macro variable and a string?

Suppose I have a dataset with variables named var1 and var1_test . I am writing a macro with input var1 . Now I am looking for a way to create var1_test from var1 and the string "_test" . Eventually, I want to use this variable in a where condition. I tried the following:

%macro some_name(var =);

   %let var2 = %sysfunc(catx(&var., '_test'));

   proc sql;
    select ...
        from ...
           where &var2. = 1;
quit;

%mend;

You don't need to use cat functions with macro variables in the macro language. They're just open text, so just putting more text next to them automatically concatenates.

%let var2 = &var._test;

You're also using the wrong CAT function, catx is for putting a delimiter in the middle so the first argument is the delimiter (so it would not concatenate anything, as it only sees one thing to concatenate). You also have quotation marks around the argument, which are not correct in %sysfunc - quotation marks in that context are treated as actual characters, not as string delimiters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM