# String replace in SAS? [closed]

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.

Thanks.

• What kind of questions can I ask here? * statistical and data-driven computing (e.g., questions about R, SAS, SPSS, Stata and Minitab) – Baltimark Mar 31 '11 at 18:01
• 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. – mpiktas Mar 31 '11 at 19:08
• @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? – whuber Mar 31 '11 at 19:54
• @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. – mpiktas Mar 31 '11 at 20:13

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.