Search code examples
functionsas

Wrong Column names on SAS


I have a table with several columns, some of which are named using numbers (e.g., 1, 2, 3, …). When I attempt to use the CATX function with these column names (e.g., CATX("+", _1, _2, _3, ..., _26)), I encounter an issue where it reports that the columns do not exist. This behavior used to work in regular SAS, but now that I’m working with SAS Grid, it no longer functions as expected. I have an error saying that those columns don't exist.


Solution

  • validvarnames=any is likely enabled, and you need to use name literals with these columns. For example:

    '1'n, '2'n, '3'n, etc.

    To use catx() on these columns, use name literal format instead:

    catx('+', of '1'n--'26'n)

    To force SAS to add an underscore on these column names, set validvarname=v7:

    options validvarname=v7;

    SAS will replace invalid characters with underscores, and add underscores in front of columns that start with numbers.