BookmarkSubscribeRSS Feed
ZRick
Obsidian | Level 7

I do see couple of examples that macro variables don't have ampersand in front of them when they are referenced.

Can you tell me under what scenario, this rule applies?

2 REPLIES 2
ballardw
Super User

I would be interested in seeing where you have found that. Any macro variable I've run across is always preceded with the ampersant. Is it possibly you are confusing a datastep automatic variable such as _n_ or _infile_ with a macro variable?

Astounding
PROC Star

There are just a handful of cases.  Here are the ones I can think of off the top of my head.

In a DATA step, CALL SYMPUT and SYMGET both expect to see the name of a macro variable.  So the ampersand should be omitted (although since it's in a DATA step, quotes would distinguish between a DATA step variable vs. a text string).  For example, both of these create a macro variable &SALES:

varname='sales';

call symput('sales', 'Friday');

call symput(varname, 'Friday');

Other than that, the only case I can think of is the %superq function.  It also expects the name of a macro variable.  For example:

data _null_;

call symput('measure', 'S&P 500 Index');

run;

%let measure = superq(measure);

title "&measure";

This would quote the &P, so that resolving &measure does not trigger a search for the macro variable &P.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register 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.

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
  • 767 views
  • 0 likes
  • 3 in conversation