Quickguide: How to import external data into SAS

Update: Quick Code.

PROC IMPORT OUT = <libname>.<dataset name> DATAFILE= “<Excel file path>”

            DBMS=EXCEL REPLACE;

 GETNAMES=YES;

RUN;

Example:

PROC IMPORT OUT= WORK.company DATAFILE= “C:\Users\Parth\Documents\SAS\SASexamples\Company_info.xlsx”

DBMS=EXCEL REPLACE;

GETNAMES=YES;

RUN;

———

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’.

data main;

run;

—-

#Tell SAS about the Contents in our data set ‘main’ and print it.

proc contents data=main;
run;

proc print data=main;
run;

—-

#Now Import your excel/csv file

proc import datafile='<<Enter the path to your file>>’

out=main replace dbms=csv;
run;

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;
run;

data home.sas_format; set work.main;
run;

—-

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.

Advertisements

About Parth Acharya
Data Analyst | Social Media Evangelist | Film Maker

One Response to Quickguide: How to import external data into SAS

  1. Shreya says:

    I am getting an error ‘ERROR: File WORK.MAIN.DATA does not exist. ‘
    ‘ERROR: Libref HOME is not assigned’

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: