0
votes

I want to change dataset names in SAS using concatenated macro variables. Using the example code below I get an error. Is my syntax wrong or is it not possible to use a concatenating function in this way?

Code:

 %let term=201610;
 %let emp='bob';

 Proc Datasets library=work;
 change testset = cat(&emp,&term);
 run;

Errors Received:

ERROR 22-322: Syntax error, expecting one of the following: ALTER, MEMTYPE, MT, MTYPE, PROTECT, PW, READ, WRITE.

ERROR 76-322: Syntax error, statement will be ignored.

1

1 Answers

1
votes

You don't need to concatenate macro variables, it's like a find and replace text. Because you have quotes right now this is what would happen:

 change testset = cat('bob', 201610)

But the CAT function is not valid there. You could technically use %SYSFUNC() to use the CAT function but there's an easier way.

 %let term=201610;
 %let emp='bob';

 Proc Datasets library=work;
 change testset = &emp&term.;
 run;quit;

Note that PROC DATASETS requires a QUIT to terminate.