Let's say I have a file A1.txt and a file A2.txt. I have written the statements

filename in1 'A1.txt';
filename in2 'A2.txt';

Now, I want to re-do this using B1 and B2 (and eventually C1, C2, D1, D2), and just rename the variable in one place. So, I want a statement like

%let prefix = 'B';

and then I want to put that prefix in the filename statements.

filename in1 '&prefix1.txt';
filename in2 '&prefix2.txt';

I'm not doing this in a data statement. I can almost get it. filename in1 &prefix'.txt' tries to read B'.txt but that extra quote is pesky. There's something vague in my memory banks about using an _ but I can't pull it out.


  • $\begingroup$ What kind of questions can I ask here? * statistical and data-driven computing (e.g., questions about R, SAS, SPSS, Stata and Minitab) $\endgroup$
    – Baltimark
    Mar 31, 2011 at 18:01
  • $\begingroup$ see the FAQ. Questions about statistical packages are usually on tricky ground, since sometimes they do not have any statistical content, but community usually answers them out of good spirits. $\endgroup$
    – mpiktas
    Mar 31, 2011 at 19:08
  • $\begingroup$ @mpiktas That's correct, but SAS seems special IMHO, because it is solely for statistics (and, AFAIK, it is not ever used by non-statisticians: who could afford to?). Where else on SE would one reasonably pose such a question and expect an answer? $\endgroup$
    – whuber
    Mar 31, 2011 at 19:54
  • $\begingroup$ @whuber, note that original comment asked about all statistical packages. I agree that SAS is different, that is why I usually upvote all the questions about it. What I wanted to say in the comment, that our community is nice, so even if question is not strictly on topic, it usually gets answered. $\endgroup$
    – mpiktas
    Mar 31, 2011 at 20:13

1 Answer 1


You are looking for a period: &prefix.1.txt, where the period after &prefix tells SAS that the name of the macro variable is finished. If you don't have the "1", then you need two periods: &prefix..txt.

  • $\begingroup$ Yes, a colleague came by and I got him to help. It was also an issue putting the name in quotes in the assignment statement. $\endgroup$
    – Baltimark
    Mar 31, 2011 at 18:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.