Developing Information on Business
PROC EXPORT
Examples:
-
Exporting a dataset to a text file
PROC EXPORT DATA=dataset;
OUTFILE='C:\...\file.txt' REPLACE;
RUN;
PROC IMPORT
Examples:
-
Importing an excel file with an odbc connection
LIBNAME work ODBC REQUIRED="Driver={Microsoft excel Driver (*.xls)}; DBQ=C:\...\file.xls; READONLY=FALSE";
DATA work.dataset;
SET work.dataset ;
RENAME x=F4;
RUN;
LIBNAME work clear;
-
importing an excel file
PROC IMPORT OUT= work.dataset1 DATAFILE= "C:\...\file.xls" DBMS=EXCEL2000 REPLACE;
RANGE="variables$";
GETNAMES=YES;DATAROW=2;
RUN;
-
importing a text file
PROC IMPORT OUT=work.dataset1 DATAFILE= 'C:\...\file.txt' DBMS=TAB REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;
-
Importing a dbf file
FILENAME dataset1 'C:\...\file.dbf';
PROC DBF DB4=dataset1 OUT=dataset2;
RUN;
-
Importing an access database
PROC IMPORT OUT= work.dataset1 DATATABLE= "table_name" DBMS=ACCESS97 REPLACE;
DATABASE="C:\...\file.mdb";
DBPWD="password";
RUN;
-
Creating a table from an odbc connection
LIBNAME SQL ODBC NOPROMPT = "dsn=sqlsrv; uid=sasjlb; pwd=password; wsid=xxxx";
PROC SQL;
CONNECT TO ODBC (dsn=sqlsrv user=user pwd=password);
CREATE TABLE dataset1 AS
SELECT * FROM CONNECTION TO ODBC
(SELECT * FROM table1);
QUIT;
-
Importing a csv file
PROC IMPORT OUT=work.dataset1 DATAFILE= 'C:\...\file.csv' DBMS=CSV REPLACE;
GETNAMES=NO;
RUN;
