user42493
user42493

Reputation: 1113

import excel sheet into SAS

I'm trying to import a (.csv)excel file that I downloaded from Kaggle into SAS by using the following codes:

PROC IMPORT OUT= Sasuser.HeartDisease DATAFILE= "C:\Users\PCPCPC\Documents\StatDatas\heart" 
            DBMS=excel REPLACE;
     SHEET="auto"; 
     GETNAMES=YES;
RUN;

However, it gives my this error:

931  PROC IMPORT OUT= Sasuser.HeartDisease DATAFILE= "C:\Users\PCPCPC\Documents\StatDatas\heart.xlsx"
932              DBMS=excel REPLACE;
933       SHEET="auto";
934       GETNAMES=YES;
935  RUN;

ERROR: Unable to open file C:\Users\PCPCPC\Documents\StatDatas\heart.xlsx. It does not  exist or it
       is already opened exclusively by another user, or you need permission to view its data.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.35 seconds
      cpu time            0.29 seconds

My files in the file system looks like this: enter image description here

Here is the properties of the file: enter image description here

Upvotes: 0

Views: 865

Answers (1)

Tom
Tom

Reputation: 51621

First thing a CSV file is not an EXCEL file, even if your operating system has chosen to use EXCEL as the default program to open files that with that extension on their filename. A CSV file is just a text file. You can view it with any text editor (including the SAS program editor). So the extension on a CSV file should be .csv.

To avoid this confusion you can tell your operating system to show you the full filenames. Here is a link to instructions for how to do this in Windows 10. https://www.thewindowsclub.com/show-file-extensions-in-windows

You can use PROC IMPORT with CSV files.

proc import 
  replace out= Sasuser.HeartDisease 
  datafile= "C:\Users\PCPCPC\Documents\StatDatas\heart.csv" 
  dbms=csv
;
run;

But because they are just plain text files you can also just write your own data step to read the file. Then you will have complete control over the variables names and how the variables are defined.

Upvotes: 1

Related Questions