1
votes

As part of a larger assignment, I'm trying to use PROC IMPORT in SAS to read in an Excel CSV file without headers or commas. I'm not sure why the CSV file doesn't have comma separators, but that was the assignment I was given. This has been my code so far:

data states;
input state $ avgRain roadLength population; 
PROC IMPORT
datafile = "C:\Users\Shane\Downloads\states1.csv" 
DBMS = CSV
getnames = no
REPLACE; 
run; 

When I do PROC PRINT, nothing happens. When I do PROC CONTENTS, it tells me only one observation was parsed in. When I try to see the table in SAS, it give me an error of "Tables with 0 columns are not supported by this object. Works.states cannot be opened"

I've also attached a screenshot of the data I'm trying to read in.

What am I doing wrong?

FL  54.5    122391  19552860
GA  50.7    127492  9992167
AL  58.3    102018  4833722
NY  41.8    114800  19651127
MI  32.8    122284  9895622
TX  28.9    313596  26448193
VT  42.7    14238   626630
OR  27.4    73479   3930065

CSV File

1
CSV stands for "Comma Delimited File". If there's no comma (or semicolon), it's not a CSV. Isn't there some other kind of delimiter? Also, the link you provide doesn't show a CSV. It shows an Excel worksheet. That doesn't help. Open it in a text editor and show us what it looks like (by copy-pasting in your post please. No screenshot)user2877959
Well the file has the extenstion .csv even though it doesn't have a comma delimiter. That's just how my professor has given it to us, and I don't think he wants us to change the file type? I've copy and pasted it in the original post.Kelsey Arthur
Your file is space/tab delimited and, in this case, fixed width. There are a few ways you can go about importing it, either with data step or proc import, as Tom pointed out in his answer.user2877959

1 Answers

3
votes

Looks like you wrote half of a data step and half of a PROC IMPORT step.

You should just pick one method

data states;
  infile "C:\Users\Shane\Downloads\states1.csv" dsd dlm='09'x truncover ;
  input state $ avgRain roadLength population; 
run;

or the other.

PROC IMPORT out=states replace 
  datafile = "C:\Users\Shane\Downloads\states1.csv" 
  DBMS = dlm
;
  getnames = no ; 
  delimiter='09'x ;
run;