PNPTestovir
PNPTestovir

Reputation: 307

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

Upvotes: 5

Views: 28968

Answers (3)

J. Zend
J. Zend

Reputation: 98

try to use `` mark... or try to use the bracket []... so it will be like library name or [library name];

select *
from sashelp.vtable 
where `library name` = xxx or [library name] = xxx;

Upvotes: 0

Andrew Lygin
Andrew Lygin

Reputation: 6197

You need to set DQUOTE=ANSI (default is DQUOTE=SAS) and then you'll be able to use quotation marks for names: "library name".

You can find details here: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473669.htm

Upvotes: 1

Y.B.
Y.B.

Reputation: 3586

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.

Upvotes: 12

Related Questions