The SAS Output Delivery System and reporting techniques

Question about the ampersand in a macro

Reply
Occasional Contributor npa
Occasional Contributor
Posts: 16

Question about the ampersand in a macro

It's been awhile since I used macros, but I recall there was a way to alter a variable or dataset name.

For example, I am using the following statement:

%macro loc(position);
.
.
proc print data=&position out=&position_t;
.
.
%mend loc;
%position(xyz)

I want dataset xyz to be read in, and I want to output the dataset xyz_t. I feel like maybe I have to put quotes around it or something, but don't recall exactly. Does anyone know what is the proper syntax to name the dataset xyz_t?
SAS Super FREQ
Posts: 8,868

Re: Question about the ampersand in a macro

Hi! Remember that you need to provide a way for the macro processor to tell when the end of the macro variable name has been reached. so if you had this:

&lib..&dsn

then the first . will signal the end of &lib and the second . will be inserted after &lib resolves. so if &lib is SASHELP and &dsn is CLASS then

&lib..&dsn would resolve to SASHELP.&dsn which would resolve to SASHELP.CLASS

So in your case, you should do:

&position._t

also, you were probably typing fast, but I thought, just in case, I'd mention that since your macro statement has
%macro LOC(position), then the correct invocation would be:

%loc(xyz)

good luck,
cynthia
Occasional Contributor npa
Occasional Contributor
Posts: 16

Re: Question about the ampersand in a macro

Posted in reply to Cynthia_sas
That's it. Thanks for the help. You're right. I was typing fast.

Thanks!
Ask a Question
Discussion stats
  • 2 replies
  • 143 views
  • 0 likes
  • 2 in conversation