Search code examples
saspass-through

SAS column name replacement scheme


I have a pass-through query using proc sql (excerpt below), in which some of the resulting names are modified since they aren't valid SAS names. 1A is replaced by _A, 2A is replaced by _A0, and some other changes are made. My questions are:

  • Is there a document which explains the rules for name replacement e.g. 2A becomes _A0?
  • Is it possible for me to change the way SAS corrects the names? For example, can I make 1A become _1A instead of _A?

.

proc sql;
connect to oracle as clc([omitted]);
CREATE table out.bk_ald as
SELECT *
FROM connection to bpm (

SELECT
  , "1A"
  , "1B"
  , "1C"
  , "1D"
  , "1E"
  , "2A"
  , "2B"
  , "2C"
...

Solution

  • You cannot change the algorithm and I am not sure if it is published. But you could either rename the column yourself on the Oracle side.

    select * from connection to oracle (select "1A" as "_1A", ...);
    

    Or rename on the SAS side. SAS will store the original name as the variable's LABEL. You could query the metadata and use that to rename the variables.

    proc contents data=bk_ald noprint out=contents; run;
    proc sql noprint ;
      select catx(name,'=',cats('_',label)) into :rename separated by ' '
      from contents 
      where upcase(name) ne upcase(label)
      ;
    quit;
    data want ;
      set bk_ald;
      rename &rename ;
    run;