Macro basics Flashcards
You can reference a macro variable anywhere is a SAS program except
in datalines
When referencing a macro variable within a title, can you use both double and single quotation marks?
No, only double quotation marks. It won’t resolve in single quotation marks
How do you display macro variable values in the SAS log using a system OPTION?
OPTIONS NOSYMBOLGEN/SYMBOLGEN;
It lists each macro variable and what it resolves to in the log.
Tell me what %PUT does and 3 important things about it
%PUT allows you to write messages to the SAS log and resolve macro variables
- writes only to the SAS log
- does not require quotation marks around text
- can be used either inside or outside a macro definition
How do you list the values of all macro variables using %PUT?
all automatic variables?
all user-generated local variables?
all user-defined macro variables?
%put _all_
%put _automatic_
%put _local_
%put _user_
What do macro quoting functions do?
Tell the macro processor to interpret special characters and mnemonics as text.
%STR is most useful for character strings that contain
- A semicolon that should be treated as text
- blanks that are significant
- a quotation mark or parenthesis without a match
%STR syntax for unmatched quotation mark, percent sign before a parenthesis and string with comment symbols
- %’ or %”, e.g. %str(Jim%’s office)
- %%) e.g. %str(20%%)
- %str(/)%str(*)comment text %str(*)%str(/)
How are NR functions different than their non-NR friends?
They also mask % and &, so they prevent macro resolution.
Use BQUOTE when
An expression has unmatching quotes
Difference between %STR and %BQUOTE
%STR performs during compilation. %BQUOTE performs during execution.
%BQUOTE doesn’t require that unmatched quotation marks be marked with a %
What function is like the %UPCASE function but also masks special characters and macro triggers?
%QUPCASE
%SUBSTR function syntax
string is the text that you want to scan
%SUBSTR(string, position, n)
What function is like the %SUBSTR function but also masks special characters and macro triggers?
%QSUBSTR
What is the result of
%let a=one; %let b=two; %let c=%nrstr(&a &b);
%put &c;
%put %substr(&c, 1, 2);
%put %qsubstr(&c, 1, 2);
Note that for %substr, the substring it finds is &a (two characters) but then this resolves to the value of a.
%put &c: &a &b
%put %substr(&c, 1, 2); one
%put %qsubstr(&c, 1, 2); &a