Panko
Panko

Reputation: 23

Using PROC IMPORT in SAS with a CSV file without headers or commas

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

Upvotes: 2

Views: 12219

Answers (1)

Tom
Tom

Reputation: 51566

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; 

Upvotes: 4

Related Questions