A SAS macro to automatically label variables using another data set
March 4, 2018 4 Comments
Introduction
When I write SAS programs, I usually export the analytical results into an output that a client will read. I often cannot show the original variable names in these outputs; there are 2 reasons for this:
- The maximal length of a SAS variable’s name is 32 characters, whereas the description of the variable can be much longer. This is the case for my current job in marketing analytics.
- Only letters, numbers, and underscores are allowed in a SAS variable’s name. Spaces and special characters are not allowed. Thus, if a variable’s name is quite long and complicated to describe, then the original variable name would be not suitable for presentation or awkward to read. It may be so abbreviated that it is devoid of practical meaning.
This is why labelling variables can be a good idea. However, I usually label variables manually in a DATA step or within PROC SQL, which can be very slow and prone to errors. I recently worked on a data set with 193 variables, most of which require long descriptions to understand what they mean. Labelling them individually and manually was not a realistic method, so I sought an automated or programmatic way to do so.
Recent Comments