Learn more how to embed presentation in WordPress
Copy and paste the code below into your blog post or website
Copy URL
Embed into WordPress (learn more)
Comments
comments powered by DisqusPresentation Slides & Transcript
Presentation Slides & Transcript
Macro
Peter’ group
Method to create macro variables
Open code using %let
Inside a macro program
Select into: in proc sql
Call symput in data step
1. Open code: using %let
The %LET statement enables you to define a macro variable and assign it a value
%LET variable = value ;
variable can be any name following SAS naming conventions
value can be any string
numeric tokens are stored as character strings,
quotes are stored as part of the value
the case of value is preserved
length range is 0-32K characters
mathematical expressions are not evaluated
leading and trailing blanks are removed from value before the assignment is made
if variable already exists, value replaces the current value
1. Open code using %let
The following version of %LOOK uses the %LET to establish two global macro variables (&DSN and &OBS).
%LET DSN = CLINICS;
%LET OBS = 10;
%MACRO LOOK;
PROC CONTENTS DATA=&dsn;
TITLE "DATA SET &dsn";
RUN;
PROC PRINT DATA=&dsn (OBS=&obs);
TITLE2 "FIRST &obs OBSERVATIONS";
RUN;
%MEND LOOK;
2. Inside a macro program
%MACRO LOOK(dsn,obs);
PROC CONTENTS DATA=&dsn;
TITLE "DATA SET &dsn";
RUN;
PROC PRINT DATA=&dsn (OBS=&obs);
TITLE2 "FIRST &obs OBSERVATIONS";
RUN;
%MEND LOOK;
2. Inside a macro program
2. Inside a macro program
%macro Count (var, var_label)
3. Select into: in proc sql
3) PROC SQL; SELECT … INTO: macrovariable …. ;
proc sql noprint;
select sum(amount) into:total from mydata;
run;
This defines a macro variable ‘total’ with a
value that is the string representing the sum of variable ‘amount’ in SAS data set mydata
4. Call symput: in data step
Store a value in a SAS macro variable
CALL SYMPUT (macro-variable, text);
This creates a macro variable named ‘macrovariable’ with a value of ‘text’.
CALL SYMPUTN (unit, 100);
This creates a macro variable named ‘unit’ with a value of 100.
More Presentations

By liquidsilk
Published Jan 14, 2013