DATA Step, Macro, Functions and more

How many ways to create 'Macros' ?

Reply
Frequent Contributor
Posts: 86

How many ways to create 'Macros' ?

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

Super Contributor
Posts: 1,636

Re: How many ways to create 'Macros' ?

are macro's and macro variables the same?

Frequent Contributor
Posts: 86

Re: How many ways to create 'Macros' ?

Nope !

Super Contributor
Posts: 1,636

Re: How many ways to create 'Macros' ?

%let var1=abcde;

Is &var1 a macro or macro variable?

Super User
Super User
Posts: 7,039

Re: How many ways to create 'Macros' ?

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.

PROC Star
Posts: 7,467

Re: How many ways to create 'Macros' ?

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

SAS Super FREQ
Posts: 8,862

Re: How many ways to create 'Macros' ?

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

PROC Star
Posts: 7,467

Re: How many ways to create 'Macros' ?

Posted in reply to Cynthia_sas

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.

Ask a Question
Discussion stats
  • 7 replies
  • 970 views
  • 1 like
  • 5 in conversation