![]() The second mandatory argument of the SYMPUT function is the value of the macro variable. Hence, the code to create unique macro variable names will look like this: ‘my_name’||LEFT(_N_). In addition, you need the LEFT function to remove (leading) blanks from the _N_ variable. You can concatenate the name and the value of the _N_ variable with the double pipe symbol (i.e., ||). If you concatenate the name of your macro variable with the value of the _N_ variable, then your macro variable will always be unique. This variable is an internal counter that stores the row number SAS is processing. To create a unique macro variable name, you can use the special variable _N_. If you omit this enumeration, SAS creates only one macro variable with the value of the last row of the dataset. Since SAS processes the observations of the input dataset sequentially, the names of your macro variables must also have some sort of enumeration. The first mandatory argument of the SYMPUT function is the name of the macro variable. You use the SET statement to specify the name of the dataset that contains the values you want to save as macro variables. With the DATA _null_ statement, SAS processes all observations from the input dataset, but it doesn’t create an output dataset. However, to create macro variables from a SAS dataset you need the special DATA _null_ statement. Normally, you use the DATA statement to create a SAS Dataset. These are the steps to save the values of a SAS variable into a macro variable The value of the macro variable is can be a text string, a number, the name of a variable of a SAS dataset, or a SAS expression.īelow we show the easiest way of using the CALL SYMPUT routine where both the macro variable name and value are a text string. As always, the name of the macro variable must comply with the SAS naming convention. ![]() The name of the macro variable is either a text string, a variable name of a SAS dataset, or a character expression that creates a text string. CALL SYMPUT(macro_variable_name = value) This function has two mandatory arguments, namely: The CALL SYMPUT routine is a combination of the CALL keyword and the SYMPUT function. Therefore, this method is perfect for creating macro variables from a dataset. This routine assigns a value produced in a Data Step to a macro variable. In the example below, we create a macro variable ( my_name) and assign it a value ( David).Ĭreate a Macro Variable with the CALL SYMPUT RoutineĪnother way to create a macro variable in SAS is by using the CALL SYMPUT routine. If you omit the value, SAS creates a null value (i.e., a macro variable of length 0). The value of the macro variable is a character string or a number. Also, the name must be 32 or fewer characters long and cannot contain blanks or special characters (except blanks). In other words, the name should start with an underscore or a letter from the Latin alphabet (A-Z, a-z). The name of the macro variable must comply with the SAS naming convention. This is the syntax of the %LET statement: %LET macro_variable_name = value You can also use the %LET statement to overwrite the existing value of a macro variable. This statement creates a macro variable and assigns it a value. The easiest way to create a macro variable in SAS is by using the %LET Macro Statement. ![]() Comparison of the %LET Macro Statement, the CALL SYMPUT Routine, and the PROC SQL INTO clause Create a Macro Variable with the %LET Statement.Create a List of Macro Variables with the PROC SQL INTO Clause.Create a Multiple Macro Variables of Different Columns with the PROC SQL INTO Clause.Create Multiple Macro Variables with the PROC SQL INTO Clause.Create a Single Macro Variable with the PROC SQL INTO Clause.Create a Macro Variable with the PROC SQL INTO Clause.What is the Difference between CALL SYMPUT and CALL SYMPUTX.Create Macro Variables from a SAS Dataset.Create a Macro Variable with the CALL SYMPUT Routine.Create a Macro Variable with the %LET Statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |