

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. If age>=18 then call symput (“status”,”adult”) Value can be the name of a variable whose value SAS will use, or it can be a constant value enclosed quotation marks.ĬALL SYMPUT is often used in if-then statements such as this: Where macro-variable-name, enclosed in quotation marks, is the name of a macro variable, either new or old, and value is the value I want to assign to that macro variable. I use CALL SYMPUT with this general form:ĬALL SYMPUT (“macro-variable-name”, value) To assign a value to a single macro variable, I can then use this macro variable in later steps. How we can call macros with in data step?ĬALL SYMPUT takes a value from a data step and assigns it to a macro variable.
#Complex sas interview questions code
How would you code a macro statement to produce information on the SAS log?ġ8. Macro parameters allow you to pass information into a macro.ġ7. How are parameters passed to a macro?Ī macro variable defined in parentheses in a %MACRO statement is a macro parameter. Every macro's beginning is identified the keyword %macro and end with %mend.ġ6.

Yes, I can execute macro within a macro, what we call it as nesting of macros, which is allowed. Can you execute macro within another macro? If so, how would SAS know where the current macro ended and the new one began? This will assign "xyz" to x, not the variable xyz to x.ġ5. Use following statement to assign the value of a rather than the variable itselfe.g. Simplest method is %LET.Įx:A, is macro variable. There are different ways of assigning a global 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. 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? They can be obtained by using symget and call symput macros.ġ4. Yes, Such macros are called nested macros. Can you execute a macro within a macro? Describe. How do you add a number to a macro variable?ġ3. %PUT is used to display user defined messages on log window after execution of a program where as % SYMBOLGEN is used to print the value of a macro variable resolved, on log window.ġ2. What is the difference between %PUT and SYMBOLGEN? What do you code to create a macro? End one?ġ1. Macro variable is used inside the Call Symput statement and is enclosed in quotes.ġ0. If you use a SYMPUT in a DATA step, when and where can you use the macro variable? Then the compiler performs the syntax check on the statement.ĩ.The compiler then requests token until it receives a semicolon.Tokens are passed on demand to the compiler.How long can a macro variable be? A token?Ī component of SAS known as the word scanner breaks the program text into fundamental units called tokens. % Local is a macro variable defined inside a macro.%Global is a macro variable defined in open code (outside the macro or can use anywhere).Ĩ. What is the difference between %LOCAL and % Global? Macros in SAS make a small change in the program and have SAS echo that change thought that program.ħ. Parameters passed to the macro program customize the results without having to change the code within the macro program. A macro program can be reused many times. We can accomplish repetitive tasks quickly and efficiently. If we want use a program step for executing to execute the same Proc step on multiple data sets. For what purposes have you used SAS macros? The end of the macro is defined by %Mend StatementĦ. How we can call macros with in data step? 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.Īfter I have defined a macro I can invoke it by adding the percent sign prefix to its name like this: % macro name a semicolon is not required when invoking a macro, though adding one generally does no harm.ģ. Have you used macros? For what purpose you have used?
