When using SAS© as an ETL to copy tables from one database to another (for example, from SQL Server to Oracle), an irritating technical limitation is often encountered: SAS© truncates variable names to 32 characters.
Modern databases support much longer column names (128 characters). A column named Identity_Source_System_Modified_On in SQL Server will be truncated to Identity_Source_System_Modified_ when processed by SAS©, which can cause naming conflicts or loss of meaning.
Here are two strategies to solve this problem: the modern method (if you have the right tools) and the manual method (if you are using a standard version of SAS©).
Method 1: The "Clean" Solution (PROC FEDSQL)
If your SAS© environment is configured with PROC FEDSQL (often available with SAS©/ACCESS or SAS© Viya™), this is the ideal solution.
Unlike the classic SAS© engine, which forces everything through the SAS© dataset format (32-character limit), PROC FEDSQL acts as a universal translator. It reads the metadata from the source and applies it to the target without being constrained by the internal limitations of SAS© datasets.
The Code
Why does it work?
FedSQL complies with the ANSI SQL standard. It maps data types and column names directly from the SQL Server engine to the Oracle engine. If both databases support 128-character names, FedSQL will preserve these names in their entirety.
Prerequisites:
Method 2: The "Workaround" Solution (PROC SQL Pass-Through)
If you don't have FedSQL or if it fails to initialize, you must use Base SAS©. The trick relies on an important detail: while SAS© truncates the variable name, it often keeps the full original name in the variable's label during ODBC/OLEDB import.
The strategy is a three-step process:
Copy the table (names will be truncated).
Identify the truncated columns by comparing the name and the label.
Dynamically generate an ALTER TABLE SQL command to rename the columns in Oracle afterward.
Step 1: Copy the table (with truncation)
Step 2: Identify Truncated Names
We will read one row from the source into a temporary table (WORK.ONE) to inspect the SAS© metadata.
Step 3: Generate and Execute the Renaming Script
We use the system table DICTIONARY.COLUMNS to find cases where the NAME (truncated) is different from the LABEL (full).
Important Note on Oracle Syntax:
The exact syntax of the ALTER TABLE command may vary depending on your Oracle version.
Ensure that your target Oracle database version supports long names (Oracle 12c R2 and later support 128 characters; earlier versions are limited to 30 characters). If your Oracle is old (v11g), even this method will fail, and you will have to shorten your names manually.
Summary
| Method | Advantages | Disadvantages |
| PROC FEDSQL | Simple, robust, no complex code. Natively preserves long names. | Requires a specific license and a compatible configuration. |
| PROC SQL + ALTER | Works with standard Base SAS©. | More complex to code. Requires ALTER permissions on the target database. Depends on the Oracle version. |