Generating new variables from variable names and values in a DATA step
September 24, 2024: 2:00 AM - 3:00 AM
Intermediate & Advanced SAS Skills, Salon A

Authors Abstract
Bruce Gilsen Writing DATA step code to transform data when new variable names are constructed from variable values can be difficult, in part because using variable values on the left-hand side of assignment statements to create new variables isn't straightforward. It's sometimes easiest to write SAS code to a file in a DATA step and then %INCLUDE the SAS code to execute it, as shown in this paper. The following techniques used in the code are described in detail: 1. Using the PROC SQL INTO clause to copy data set values to a macro variable or series of macro variables. 2. Writing intermediate results to a temporary file (including why this is beneficial). 3. Using the little-known SAS-provided TSLIT macro to avoid needing double quotation marks around literal text that contains quotes, greatly simplifying processing. 4. Processing all elements of an array in a DATA step function or CALL routine with the OF operator.

Paper