BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
emptyhead
Calcite | Level 5

Hello everyone, I really need some advise. I have table whose column names are numbers and I can't change this setting. Now I am trying to find a solution how to union this table with others in SAS Studio. Here's what I got so far:

options msglevel=i;
options noquotelenmax;
options validvarname=ANY; /* for variables*/  

filename genFuncs FILESRVC folderpath='/department/lib_name' filename='general_functions_v2.sas';
%include genFuncs / source;

proc cas;
  %casFunctions;
  
  outCaslibName="lib_name";
  casTableName="table_union";
  tmpTableName = casTableName || "_" || rand("Integer", 111111, 999999);

  createTableString="create table lib_name." || tmpTableName ||" {options replace=true} as (

 select v.month from lib_name.normal_table v
 union all
 select t.'198'n from lib_name.uqly_table t
  )";

and I can't convince SAS, that '198'n is the month column name.
errorerror

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

I do not use CAS language, but it looks to me like you are creating a character variable that happens to contain what looks like SQL syntax.   If it is just a string then the content shouldn't matter.  So somewhere under the hood the string must have been used by some SQL process.  Perhaps that SQL process would rather that you use ANSI style double quotes around invalid names?

 

Try:

createTableString
   ="create table lib_name." || tmpTableName
  ||" {options replace=true} as ("
  ||"select v.month from lib_name.normal_table v "
  ||" union all "
  ||"select t.""198"" from lib_name.uqly_table t"
  ||")"
;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

I do not use CAS language, but it looks to me like you are creating a character variable that happens to contain what looks like SQL syntax.   If it is just a string then the content shouldn't matter.  So somewhere under the hood the string must have been used by some SQL process.  Perhaps that SQL process would rather that you use ANSI style double quotes around invalid names?

 

Try:

createTableString
   ="create table lib_name." || tmpTableName
  ||" {options replace=true} as ("
  ||"select v.month from lib_name.normal_table v "
  ||" union all "
  ||"select t.""198"" from lib_name.uqly_table t"
  ||")"
;
emptyhead
Calcite | Level 5

Thousand thanks, it works!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 990 views
  • 1 like
  • 3 in conversation