How to import CSV File into SAS in Windows/Unix/Mac

How to import CSV File into SAS ?

Import CSV File into SAS – In SAS one of the most common way to import CSV File is done using proc import procedure and here we are sharing the tutorial How to import CSV File into SAS using proc import in different operating system.

If you are working on SAS® Studio then you have first upload your .CSV File into SAS Studio then replace this <Your CSV File> with your “/home/trenovision/Filename.csv”

If you are working on server then you have to provide complete server path where the .csv file resides i.e. “/sasxxapp/data/Filename.csv”

/** FOR CSV Files uploaded from Windows **/

FILENAME CSV "<Your CSV File>" TERMSTR=CRLF;

/** FOR CSV Files uploaded from Unix/MacOS **/

FILENAME CSV "<Your CSV File>" TERMSTR=LF;

/** Import the CSV file. **/

PROC IMPORT DATAFILE=CSV
OUT=WORK.MYCSV
DBMS=CSV
REPLACE;
RUN;

/** Import the CSV file without FILENAME method **/

PROC IMPORT DATAFILE="<Your CSV File>"
OUT=WORK.MYCSV
DBMS=CSV
REPLACE;
RUN;

/** Print the results. **/

PROC PRINT DATA=WORK.MYCSV; RUN;

/** Unassign the file reference. **/

FILENAME CSV;

where

FILENAME -> It is used to store .CSV Filename.

TERMSTR ->This option is used to define the operating system from which we’re importing file.

DATAFILE -> Specifies the complete path and filename or fileref for the input PC file, spreadsheet, or delimited external file.

OUT -> This option tell SAS where to store the imported File.

DBMS -> Specifies the type of data to import.

REPLACE -> Overwrites an existing SAS data set. If you do not specify REPLACE, PROC IMPORT does not overwrite an existing data set.