Needhelp
Needhelp

Reputation: 11

How to create data set by the reference csv file

data name
filename reference name  "filename.csv"
infile filename.csv dlm=",";
run;

what is wrong with the code?How to create data set by the reference csv file

Upvotes: 1

Views: 129

Answers (1)

Richard
Richard

Reputation: 27516

Place the filename statement before the DATA Step.

You will need an INPUT statement to read the data into variables, or if the file has a header row use Proc IMPORT and the system will best guess the input needed.

Example 1

Presume file has no header row and there are 3 columns of numbers separated by commas

  filename myfile 'mydatafile.csv';
  data want;
    infile myfile dsd dlm=',';
    input x y z;
  run;

Example 2

Presume there is a header row

  filename myfile 'mydatafile.csv';
  proc import file=myfile replace out=want dbms=csv;
  run;

or

  * columns expected are known;
  filename myfile 'mydatafile.csv';
  data want;
    infile myfile dsd dlm=',' firstobs=2;
    input x y z;
  run;

NOTE

An INFILE statement can also directly refer to a file

   ...
   INFILE "filename.csv" ... ;
   ...

Upvotes: 1

Related Questions