DATA Step, Macro, Functions and more

Proc import csv specify a row for headers and a row for the first observation

Reply
Frequent Contributor
Posts: 127

Proc import csv specify a row for headers and a row for the first observation

Dear SAS experts,

 

which ist the easiest way to import a csv specifying:

- in wich row are the headers

- in which row start the data

 

I tried in several ways (dataeow, firstobs...) But I do not gest what i want.

for instance:

proc import datafile='test.csv'

  datarow=3; getnames=yes;

run;

 

Attached an example of the csv input and the data that I would like to get in SAS.

Super User
Posts: 11,343

Re: Proc import csv specify a row for headers and a row for the first observation

Posted in reply to Sir_Highbury

Reading variable names from the CSV requires that the name be on a single row. Easiest is to Edit the CSV to remove the entire first line with the column headers like "Platin/EURO".

Then datarow=2 should work fine.

Frequent Contributor
Posts: 127

Re: Proc import csv specify a row for headers and a row for the first observation

Hi ballardw,

thank but this is what I am currently doing and I would not.

So means that SAS cannot do it?

Respected Advisor
Posts: 3,799

Re: Proc import csv specify a row for headers and a row for the first observation

Posted in reply to Sir_Highbury

Use a data step to write a new copy of the file with the record(s) edited as you see fit.  Then run your PROC IMPORT on that.

Super User
Posts: 11,343

Re: Proc import csv specify a row for headers and a row for the first observation

Posted in reply to Sir_Highbury

Sir_Highbury wrote:

Hi ballardw,

thank but this is what I am currently doing and I would not.

So means that SAS cannot do it?


Show the exact code you run, the Log results and  show the data as a TXT file not Excel (it may change values with out telling you).

 

You should always use a fully qualified path to point to input and out file locations : datafile = "C:\somefolder\otherfolder\inputfile.csv" for example instead of  datafile="test.csv" as the later is going to read from what SAS considers the current active folder and is very likely not the location you expect.

Super User
Super User
Posts: 7,076

Re: Proc import csv specify a row for headers and a row for the first observation

Posted in reply to Sir_Highbury

For a file with three variable just write the data step yourself.  Probably will take less code than the the PROC IMPORT statements.

data want ;
   infile "myfile.csv" dsd firstobs=3 truncover ;
   length date field1 field2 8 ;
   informat date mmddyy10.;
   format date yymmdd10.;
   input date field1 field2;
run;
Ask a Question
Discussion stats
  • 5 replies
  • 935 views
  • 0 likes
  • 4 in conversation