Professional Documents
Culture Documents
1. Have you used macros? For what purpose you have used?
Yes I have, I used macros in creating datasets and tables where it is necessary to make a small
change through out the program where it is necessary to use the code and again.
9. If you use a SYMPUT in a DATA step, when and where can you use the macro variable?
Macro variable is used inside the Call Symput statement and is enclosed in quotes.
14. If you need the value of a variable rather than the variable itself what would you use to
load the value to a macro variable?
If we need a value of a macro variable then we must define it in such terms so that we can call
them everywhere in the program. Define it as Global. There are different ways of assigning a
global variable. Simplest method is %LET.
Ex:A, is macro variable. Use following statement to assign the value of a rather than the variable
itselfe.g.
%Let A=xyzx="&A";
15. Can you execute macro within another macro? If so, how would SAS know where the
current macro ended and the new one began?
Yes, I can execute macro within a macro, what we call it as nesting of macros, which is allowed.
Every macro's beginning is identified the keyword %macro and end with %mend.
17. How would you code a macro statement to produce information on the SAS log?
This statement can be coded anywhere?
OPTIONS, MPRINT MLOGIC MERROR SYMBOLGEN;
These statements create a macro variable named &status and assign to it a value of either adult or
minor depending on the variable age.Caution: We cannot create a macro variable with CALL
SYMPUT and use it in the same data step because SAS does not assign a value to the macro
variable until the data step executes. Data steps executes when SAS encounters a step boundary
such as a subsequent data, proc, or run statement.
The use of %include does not actually set up a library. The %include statement points to a file
and when it executed the indicated file (be it a full program, macro definition, or a statement
fragment) is inserted into the calling program at the location of the call. When using the
%include building a macro library, the included file will usually contain one or more macro
definitions.%EVAL is a widely used yet frequently misunderstood SAS(r) macro language
function due to its seemingly simple form.
However, when its actual argument is a complex macro expression interlaced with special
characters, mixed arithmetic and logical operators, or macro quotation functions, its usage and
result become elusive and problematic. %IF condition in macro is evaluated by %eval, to reduce
it to true or false.
21. Describe the ways in which you can create macro variables?
There are the 5 ways to create macro variables:
%Let
%Global
Call Symput
Proc SQl
Parameters.
25. What system options would you use to help debug a macro?
Debugging a Macro with SAS System Options. The SAS System offers users a number of useful
system options to help debug macro issues and problems. The results associated with using
macro options are automatically displayed on the SAS Log.
Specific options related to macro debugging appear in alphabetical order in the table below.SAS
Option Description:
MEMRPT Specifies that memory usage statistics be displayed on the SAS Log.
MERROR: SAS will issue warning if we invoke a macro that SAS didn’t find. Presents
Warning Messages when there are misspellings or when an undefined macro is called.
SERROR: SAS will issue warning if we use a macro variable that SAS can’t find.
MLOGIC: SAS prints details about the execution of the macros in the log.
MPRINT: Displays SAS statements generated by macro execution are traced on the SAS Log
for debugging purposes.
SYMBOLGEN: SAS prints the value of macro variables in log and also displays text from
expanding macro variables to the SAS Log.
26. If you need the value of a variable rather than the variable itself what would you use to
load the value to a macro variable?
If we need a value of a macro variable then we must define it in such terms so that we can call
them everywhere in the program. Define it as Global.
There are different ways of assigning a global variable.
Simplest method is %LET.
Ex:A, is macro variable. Use following statement to assign the value of a rather than the variable
itselfe.g.
%Let A=xyzx="&A";
This will assign "xyz" to x, not the variable xyz to x.
27. Can you execute macro within another macro? If so, how would SAS know where the
current macro ended and the new one began?
Yes, I can execute macro within a macro, what we call it as nesting of macros, which is allowed.
Every macro's beginning is identified the keyword %macro and end with %mend.
29. How would you code a macro statement to produce information on the SAS log?
This statement can be coded anywhere?
OPTIONS MPRINT MLOGIC MERROR SYMBOLGEN;
32. What are the macros you have used in your programs?
Used macros for various puposes, few of them are..
1) Macros written to determine the list of variables in a dataset:
%macro varlist (dsn);
proc contents data = &dsn out = cont noprint;
run;
3) Written macros for sorting common variables in various datasets%macro sortit (datasetname,
pid, investigator, timevisit)
PROC SORT DATA = &DATASETNAME;
BY &PID &INVESTIGATOR;
%mend sortit;
33. What is auto call macro and how to create a auto call macro? What is the use of it?
How to use it in SAS with macros?
SAS Enables the user to call macros that have been stored as SAS programs.
The auto call macro facility allows users to access the same macro code from multiple SAS
programs. Rather than having the same macro code for in each program where the code is
required, with an autocall macro, the code is in one location. This permits faster updates and
better consistency across all the programs.Macro set-up:The fist step is to set-up a program that
contains a macro, desired to be used in multiple programs. Although the program may contain
other macros and/or open code, it is advised to include only one macro.