![]() ![]() There are some system options that can be used to debug SAS Macros: 1. In this case, we have used comma(,) as a delimiter. %put &myvar returns Deepanshu Bhalla,Dave Jhonson,Ram Prasad It can be done by using SEPARATED BY ' ' keyword in PROC SQL. Suppose you have a list of names and you want to store them in a macro variable. How to store list of values in a macro variable So var1 returns 25 Detailed Tutorial : Multiple Ampersand Macro Variables &z returns 25 because first & resolves to &, &x resolves to var, &y. Suppose you have 3 macro variables and the third variable is actually a concatenation of the first 2 variables' value. The %SCAN function returns the nth word in a string. In the above case, %NRSTR() stops the &SYSDATE9 macro function. ![]() %put "Difference between %NRSTR(&SYSDATE9) and &SYSDATE9" Result : "Difference between &SYSDATE9 and 23DEC2016" %NRSTR works similar to %STR works except it does not resolve the % and & but stop the macro triggers. Run the above code and compare it with the code below, you would understand the difference. Usage III : It also preserves leading and trailing blanks of the string. If you would not use %STR function in the above example, you would not be able to store quotes in a macro variable. Usage II : Precede with % sign when you use single or double quotation in macro To workaround this issue, let's use %STR function. ![]() Since the semicolon following PRINT terminates the %LET statement. Suppose we need to store PROC PRINT RUN command in a macro variable. Usage I : This function removes the normal meaning of following token + – * /, > < = “ LT EQ GT LE GE LE NE AND OR NOT blank. There are several useful Base SAS function that are not directly available in Macro, %Sysfunc enables those function to make them work in a macro. It is when the %SYSEVALF function comes into picture. %let last = %eval (4.5+3.2) returns error as it cannot perform arithmetic calculations with operands that have the floating point values. It is used to perform mathematical and logical operation with macro variables. There are some SAS macro functions which help you to execute various operations within a macro. Tutorial : Difference between IF THEN and %IF %THEN If you are confused between IF-THEN and %IF-THEN and don't know when to use, check out the link below. In SAS Macros, we can apply conditional statements using %IF %THEN like below. %mend calcl How to use conditional processing %IF %THEN ? In this case, we are giving flexibility to users to provide information of input dataset name, the analysis variable and output dataset and the macro returns the mean value of the analysis variable in the output dataset.Įxample : Suppose you are asked to calculate average height and store in a macro variable. %test(input=sashelp.heart, ivar= height, output=test) In the above code, test is a macro input, ivar and output are local macro variables. The analysis variable, input and output data sets are dynamic. Suppose you are asked to write a macro that returns mean value of a variable. The quotes are not needed because, unlike in the DATA step, the macro facility does not need to distinguish between variable names and text strings. Notice that unlike the PUT statement the text string is not enclosed in quotes. To view in log window what macro variable would return, use %PUT statement : ![]() Macro variables are referenced by using ampersand (&) followed by macro variable name. %let dt = &sysdate How to use Macro Variables %LET macro-variable-name = value %LET x = 5 Example - To store system date. The syntax of the %LET statement is as follows. The %LET can defined inside or outside a macro. The following is a list of various ways to create a macro variable in SAS, along with examples. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |