Search code examples
sqlcastingsaspass-through

sas sql pass-through to macro variable as a character


How to read macro variable as a character in SAS SQL pass-through

My goal is to put "one" as the only value in var3 , but now i get

"unknown column one"

 %macro test(notvar=)

proc sql;
      connect to odbc as conn (datasrc=x user=&user1. password=&pwd1.);
      create table &notvar. (compress=no) as select * from connection to conn
      (
            select var1, var2,
            &notvar. as var3
            from table1
      );
disconnect from conn;
quit;

%mend test;

%test(notvar=one);

Solution

  • Haven't tested though. I think you can put the macro variable as value of column like:

     select var1, var2,
     "&notvar" as var3
     from table1
    

    or

     select var1, var2,
     symget('notvar') as var3
     from table1
    

    If no quotation mark or function for fetching macro variable value is specified, the selected object ("one" here in your case) is regarded as a column in the original table. So you get error for there is no such column.