SAS Helpful Hints
SAS Macro Language and Functions
SAS Macros are a language of character variables.
%Let mytitle=Macro Variables!;
Title1 "&mytitle";
Performing arithmatic with character variables can be difficult, but
not impossible.
%Let pagenumber=%Eval(&pagenumber+1);
Options Pageno=&pagenumber;
SAS Macros procedures are powerful tools to perform repetitive tasks.
Quick Example:
%Macro plot(dataset, xvar, yvar);
Proc Plot Data=&dataset;
Plot &xvar*&yvar;
Run;
%Mend plot;
%plot(work.A, age, education);
%plot(work.B, sat, gmat);
See our macro library for other examples. Here is
a quick reference guide to some of the SAS macro language elements.
| |
| %Let |
Assignment |
| %Put |
Write (to Log file by default) |
| %If %Then %Else |
If Then Else |
| %Do %To %End |
Incremental do loop |
| %Do %While() %End |
While loop |
| %Do %Until() %End |
Until loop |
| %Macro %Mend |
Macro Definition |
| |
| %Eval() |
433=%Eval(124+315-6) |
| %Sysevalf() |
0.25=%Sysevalf(1.0/4.0) |
| %Index(,) |
5=%Index(a string,r) |
| %Length() |
8=%Length(a string) |
| %Cmpres() |
trimmed=%Cmpres( trimmed ) |
| %Upcase() |
HELP=%Upcase(help) |
| %Lowcase |
help=%Lowcase(HELP) |
| %Sysfunc() |
Calls a SAS language Function |
| SAS Language Procedure |
Call Symput(“mx”,x);
|
Creates a Macro variable from
a datastep |
| SAS Macro Variables |
| &Sysday |
Today: Sunday-Saturday |
| &Sysdate |
Today's date: 12NOV01 |
| &Sysdate9 |
Today's date: 14DEC2001 |
Please send your comments and suggestions about this web page to A. Watts
(watts@bst.rochester.edu)
|