BookmarkSubscribeRSS Feed
Grandhi4
Calcite | Level 5

Hi,

How many ways to create a Macro's ?

I Know couple of it like....

%Macro,

% Let

% Local

% Global

Call symput (Data setp)

Into clause  (sql)

% Do

is there any other ways ?

Thanks,

Suresh

7 REPLIES 7
Linlin
Lapis Lazuli | Level 10

are macro's and macro variables the same?

Grandhi4
Calcite | Level 5

Nope !

Linlin
Lapis Lazuli | Level 10

%let var1=abcde;

Is &var1 a macro or macro variable?

Tom
Super User Tom
Super User

Most of those create macro variables.  Only %macro ... %mend can create an actual SAS macro.

There are procedure that will set macro variable values (and create the macro variable if they have to).

PROC SQL

PROC REPORT

Some statements such as

LIBNAME

FILENAME

might also set macro variable values.

art297
Opal | Level 21

Tom: Not quite true!  There is also the old style macro!  E.g.;

macro print means%

proc print data=sashelp.class;

  var height;

run;

%deact print;

proc print data=sashelp.class;

  var height;

run;

which will produce:

                         The MEANS Procedure

                         Analysis Variable : Height

      N            Mean         Std Dev         Minimum         Maximum

     ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

     19      62.3368421       5.1270752      51.3000000      72.0000000

     ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

and then:

                             Obs    Height

                                 1     69.0

                                 2     56.5

                                 3     65.3

                                 4     62.8

                                 5     63.5

                                 6     57.3

                                 7     59.8

                                 8     62.5

                                 9     62.5

                                10     59.0

                                11     51.3

                                12     64.3

                                13     56.3

                                14     66.5

                                15     72.0

                                16     64.8

                                17     67.0

                                18     57.5

                                19     66.5

Cynthia_sas
SAS Super FREQ

Hi:

  As you can see from the various responses, using the term "macro" leaves the term open to interpretation and confusion. There are MACRO PROGRAM definitions, which usually are created by using %MACRO and %MEND -- I would say this is the primary method (or using Art's technique for "old style" macro programs).

  Then, there are MACRO VARIABLE definitions. Some methods to create MACRO VARIABLES are explicit, such as INTO, %LET or CALL SYMPUT, however, some methods of creating MACRO VARIABLES are implicit, such as the fact that the index variable for a macro language %DO loop will become a usable macro variable.

  Personally, I find the macro language section of the documentation to be quite thorough and comprehensive in the discussion of the difference between macro variables and macro programs. I'd suggest that you start there to answer your question.

cynthia

art297
Opal | Level 21

Cynthia (and everyone),  I wasn't suggesting that anyone use "old style" macros, I was just making sure that it got added to Tom's list of "possible ways" to create a macro program.  I have only seen one case where an "old style" macro turned out to be the only solution to a problem and that was to substitute text in order to override a particular setting in one proc.

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
  • 7 replies
  • 3667 views
  • 2 likes
  • 5 in conversation