Quoted List Separated by Spaces

How to Create a Quoted List Separated by Spaces in SAS

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.

Program Steps

  • Initialize a DATA step to process a data set containing the values to be placed in the list.
  • Use the CALL SYMPUTX function to create a macro variable called &MAC.
  • Inside the CALL SYMPUTX function, use the QUOTE function to enclose the value of the data set variable fruits in quotes.
  • Apply the STRIP function to remove any leading or trailing blanks within the quoted value.
  • Place the resulting value inside the macro variable &MAC.
  • Use the CALL EXECUTE function to dynamically generate a %LET statement 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;

Output:

Quoted List Separated by Spaces
Quoted List Separated by Spaces

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.

Every week we'll send you SAS tips and in-depth tutorials

JOIN OUR COMMUNITY OF SAS Programmers!

Subhro

Subhro provides valuable and informative content on SAS, offering a comprehensive understanding of SAS concepts. We have been creating SAS tutorials since 2019, and 9to5sas has become one of the leading free SAS resources available on the internet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.