Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sentry Page Protection
Please Wait...
SAS Macro [2-15]


Referencing Macro Variable in Title
Referencing macro variable in title or footnotes requires special attention.

You must use double quotation when the title (or footnotes) includes a reference to the macro variable.

Example

Copy and run the TRANSAC data set from the yellow box below. 
Picture

The TRANSAC data set contains a list of transactions, agents and transaction amount:
  • TranID: Transaction ID
  • Agent: Tom, Mary or John
  • Amount: Transaction Amount

The code below computes the summary statistics (i.e. n, mean, standard deviation) for the transaction amount by the agent John.

Example

Title "Transaction Statistics: John";
​
Footnote1 "The table shows the transaction statistics by John.";

proc means data=transac;
var amount;
where agent = "John";
run;
Picture

The program looks great. It computes the transaction statistics for John with the correct title and footnote.

Now, let's add the proper macro variable to the program so that it is reusable for the other two agents.

Example

%let agent = John;

​Title "Transaction Statistics: &agent";
​
Footnote1 "The table shows the transaction statistics by &agent.";

proc means data=transac;
var amount;
where agent = "&agent";
run;

This computes the same statistics as before (John).
Picture

Now, let's use the program to compute the statistics for Mary:

Example

%let agent = Mary;

​Title "Transaction Statistics: &agent";
​
Footnote1 "The table shows the transaction statistics by &agent.";

proc means data=transac;
var amount;
where agent = "&agent";
run;
Picture

By simply assigning a different value to the macro variable AGENT, the program now computes the statistics for Mary instead.


No Quotation Needed

Please note that when assigning the text value (e.g. John, Mary) to the macro variable, no quotation was used:

Example

%let agent = John;
%let agent = Mary;


Picture

​It is then inserted into your program where the macro variable was referenced (&dur):
Picture

When the program is executed, the macro variable reference (&dur) will be replaced by the value assigned to the macro variable (i.e. 20).

This will be the same as executing the following program instead:
Picture

Substituting text with macro variables is fairly easy.

In the next few sessions, you will learn a few more examples of how macro variables can make your program more dynamic and reusable.

Exercise

Reuse the program above and print the list of subscribers whose length of membership is less than 30 days.
Next

Need some help? 

Get Hint
Get Solution

Fill out my online form.

Home 
​1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Summary | Final Test | Coding Exercises
Already a member? Go to member's area.