0

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;
3
  • 1
    Try this: %let var2 = &var._test; Commented Feb 1, 2017 at 14:16
  • Very simple. Thank you :-) Commented Feb 1, 2017 at 15:35
  • Are you trying to create a macro variable named var2 or do you want the name to be var1_test ? Or doesn't it matter as long as it can go down into the WHERE clause? Commented Feb 1, 2017 at 22:00

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.