Search code examples
sqlsas4gl

Proc SQL with space in the column name


How I can use column with space in the name ('library name') in PROC SQL in SAS?

proc sql outobs=10;
    select *
    from sashelp.vtable 
    where library name = xxx
    ;
run;

I tried:

proc sql outobs=10;
    select *
    from sashelp.vtable 
    where 'Libname'n = test_lin;
quit;

proc sql outobs=10;
    select *
    from sashelp.vtable 
    where 'library name'n = test_lin;
quit;

proc sql outobs=10;
    select *
    from sashelp.vtable 
    where libname = test_lin;
quit;

ERROR: The following columns were not found in the contributing tables: test_lin.

sashelp.vtable

Variable Name: libname

Variable Label: Library Name


Solution

  • According to documentation - SAS Name Literals:

    proc sql outobs=10;
        select *
        from sashelp.vtable 
        where 'library name'n = xxx
        ;
    run;
    

    A SAS name literal is a name token that is expressed as a string within quotation marks, followed by the upper- or lowercase letter n. ... You can use a name literal only for variables, statement labels, and DBMS column and table names.