BookmarkSubscribeRSS Feed
npa
Calcite | Level 5 npa
Calcite | Level 5
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?
2 REPLIES 2
Cynthia_sas
Diamond | Level 26
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
npa
Calcite | Level 5 npa
Calcite | Level 5
That's it. Thanks for the help. You're right. I was typing fast.

Thanks!

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2004 views
  • 0 likes
  • 2 in conversation