In this article, we will walk you through the process of creating a quoted list separated by spaces in SAS.
Here is an example dataset:
data one; input fruits $30.; datalines; apples bananas pears grapes ; run;
This example illustrates how to create a space-separated list that is quoted using the techniques of CALL SYMPUTX and CALL EXECUTE routines.
- Initialize a DATA step to process a data set containing the values to be placed in the list.
- Use the
CALL SYMPUTXfunction to create a macro variable called &MAC.
- Inside the CALL SYMPUTX function, use the
QUOTEfunction to enclose the value of the data set variable fruits in quotes.
- Apply the
STRIPfunction to remove any leading or trailing blanks within the quoted value.
- Place the resulting value inside the macro variable &MAC.
- Use the
CALL EXECUTEfunction to dynamically generate a
%LETstatement for each observation in the data set.
- Inside the %LET statement, append the value of &MAC onto the previous value of &LIST (which is initially null).
%let list=; data _null_; set one; call symputx('mac', quote(strip(fruits))); call execute('%let list=&list &mac'); run; %put &=list;
In conclusion, creating a quoted list separated by spaces is a common task when working with SAS. This type of list can be used in various scenarios, such as passing parameters to a macro or generating code dynamically.
To create a quoted list separated by spaces in SAS, we can use the combination of the QUOTE, STRIP, CALL SYMPUTX, and CALL EXECUTE functions. The QUOTE function is used to add quotes to the list values, while the STRIP function removes any leading or trailing blanks.
CALL SYMPUTX creates a macro variable for each value in the list, and CALL EXECUTE is used to generate %LET statements that append each value to the previous values in the list.
By following these steps, we can easily create a quoted list separated by spaces that can be used in various SAS programs.