Quickguide: How to import external data into SAS
November 30, 2012 1 Comment
Update: Quick Code.
PROC IMPORT OUT = <libname>.<dataset name> DATAFILE= “<Excel file path>”
PROC IMPORT OUT= WORK.company DATAFILE= “C:\Users\Parth\Documents\SAS\SASexamples\Company_info.xlsx”
Original Blog Begins Here:
Here is the code to get external data (csv, xls, txt) into your SAS environment.
The basic objective is to get your *.csv or *.xls file converted to *.sas7bdat format (which is the default extension for SAS EnterpriseMiner)
Open SAS (not EnterpriseMiner).
After opening SAS, go to the Editor and type the following line of codes:
IMPORTANT NOTE: After writing each block of codes, select the written code and click the ‘run’ button.
NOTE: The terms in Bold should be colored (mostly blue).
#We will first create an empty data set called ‘main’.
#Tell SAS about the Contents in our data set ‘main’ and print it.
proc contents data=main;
proc print data=main;
#Now Import your excel/csv file
proc import datafile='<<Enter the path to your file>>’
out=main replace dbms=csv;
example for procedure: proc import datafile=’C:\Downloads\MIS6324BI\Titanic Data\train.csv’
Note: ‘out=main’ because the data set we created is named as ‘main’.
Note: If the file you want to import is Excel, type- “dbms=excel”
#Create a new library
libname home “<<Path of your wish to the library>>”;
example: libname home “C:\Users\parth\Documents\My SAS Files\”
#Run the following codes in order to get the imported file into your ‘main’ data set. And then to get your newly created ‘main’ data into the above created library.
data sas_format; set home.main;
data home.sas_format; set work.main;
The resulting SAS format files will be in the library path you have given to SAS. In this case- ‘C:\Users\parth\Documents\My SAS Files\’
Please do comment on this post if you find any problem following the steps to import data into SAS.