The message "ERROR: The variable name ... is illegal" appears when ordinal variable names exceed the 32-character limit


Using the JSON LIBNAME engine, SAS generates variable names that exceed the 32-character limit when processing JSON keys with identical prefixes, resulting in errors similar to the following:

ERROR: The variable name ordinal_xxxxxxxxxxxxxxxxxxxxxxxx1 is illegal.

This error typically occurs during dataset creation (such as with PROC COPY) and prevents the JSON data from being successfully loaded into SAS tables.

Cause

The JSON LIBNAME engine derives SAS variable names from JSON keys.

When multiple JSON keys share identical leading characters, the engine might do the following:

In some scenarios, the resulting variable name exceeds the SAS limit of 32 characters, making it invalid and causing failures in procedures accessing the JSON libref.

SAS variable naming rules enforce a maximum length of 32 characters.

Workarounds

Method 1: Modify JSON Keys

Ensure that JSON keys conform to the following:

Method 2: Use a JSON Map

Define explicit variable names that are shorter than 32 characters using a JSON map file. Refer to LIBNAME Statement: JSON Engine for examples and syntax to create a map file.