This example creates a DBMS
table with a blank space in its name. Double quotation marks are used
to specify the table name, International Delays. You can also set
both of the preserve names LIBNAME options by using the alias PRESERVE_NAMES=.
Because PRESERVE_NAMES=YES, the schema airport is now case sensitive
for Oracle.
options linesize=64 nodate;
libname mydblib oracle user=testuser password=testpass path='airdata'
schema=airport preserve_names=yes;
proc sql dquote=ansi;
create table mydblib."International Delays" as
select int.flight as "FLIGHT NUMBER", int.dates,
del.orig as ORIGIN,
int.dest as DESTINATION, del.delay
from mydblib.INTERNAT as int,
mydblib.DELAY as del
where int.dest=del.dest and int.dest='LON';
quit;
proc sql dquote=ansi outobs=10;
title "International Delays";
select * from mydblib."International Delays";
You can use single
quotation marks to specify the data value for London (
int.dest='LON'
)
in the WHERE clause. Because of the preserve name LIBNAME options,
using double quotation marks would cause SAS to interpret this data
value as a column name.
DBMS Table with Nonstandard Column Names
International Delays
FLIGHT
NUMBER DATES ORIGIN DESTINATION DELAY
-----------------------------------------------------------
219 01MAR1998:00:00:00 LGA LON 18
219 02MAR1998:00:00:00 LGA LON 18
219 03MAR1998:00:00:00 LGA LON 18
219 04MAR1998:00:00:00 LGA LON 18
219 05MAR1998:00:00:00 LGA LON 18
219 06MAR1998:00:00:00 LGA LON 18
219 07MAR1998:00:00:00 LGA LON 18
219 01MAR1998:00:00:00 LGA LON 18
219 02MAR1998:00:00:00 LGA LON 18
219 03MAR1998:00:00:00 LGA LON 18
If you query a DBMS
table and use a label to change the FLIGHT NUMBER column name to a
standard SAS name (Flight_Number), a label (enclosed in single quotation
marks) changes the name only in the output. Because this column name
and the table name (International Delays) each contain a space in
their names, you must enclose the names in double quotation marks.
Partial output follows the example.
options linesize=64 nodate;
libname mydblib oracle user=testuser password=testpass path='airdata'
schema=airport preserve_names=yes;
proc sql dquote=ansi outobs=5;
title "Query from International Delays";
select "FLIGHT NUMBER" label='Flight_Number', dates, delay
from mydblib."International Delays";
Query Renaming a Nonstandard Column to a Standard SAS Name
Query from International Delays
Flight_
Number DATES DELAY
--------------------------------------
219 01MAR1998:00:00:00 18
219 02MAR1998:00:00:00 18
219 03MAR1998:00:00:00 18
219 04MAR1998:00:00:00 18
219 05MAR1998:00:00:00 18
You can preserve special
characters by specifying DQUOTE=ANSI and using double quotation marks
around the SAS names in your SELECT statement.
proc sql dquote=ansi;
connect to oracle (user=testuser password=testpass);
create view myview as
select "Amount Budgeted$", "Amount Spent$"
from connection to oracle
(select "Amount Budgeted$", "Amount Spent$"
from mytable);
quit;
proc contents data=myview;
run;
Output from this example
would show that Amount Budgeted$ remains Amount Budgeted$ and Amount
Spent$ remains Amount Spent$.