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
SAS Super FREQ
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!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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