BookmarkSubscribeRSS Feed
Calcite | Level 5

We have a utility that creates a large number of CSV files. The utility puts the type of data in that CSV file in row-1 (for example: 'PDEVINFO' or 'LDEVINFO') and the column headings are in row-2.

What I have is:

proc import

     datafile = 'where it is'


     dbms = csv;

     getnames = yes;

     datarow = 3;

     guessrows = 1000;


proc print data=Work.PDEVINFO uniform;



What it is doing is getting the value 'PDEVINFO' from row-1 and treating that as a column header and then all other columns it generates variable names as     VAR1, VAR2,....

Is there a simple way of telling it to get the column headings from row-2?

Quartz | Level 8

One solution is to remove the first line before Proc Import.  It means that the files get read twice, which for many large files can be an issue.

filename have '<existing CSV>' ;

filename want '<edited CSV>' ;

data _Null_ ;

     infile have ;

     file want ;

     input ;

     if _N_ = 1 then return ;

     put _infile_ ;

Run ;

If you are using base SAS rather then EG it is possible to do a Proc Import, then press F4 to retrieve the submitted code (which is just a SAS datastep) and edit it to skip the first line.  Then use the edited datastep instead of Proc Import.  Only worth doing if all your files have the same layout and column names, and the layout/names are unlikely to change..


Quartz | Level 8

Also, you probably will need to set LRECL= 9999 or some large number on the filename statements to avoid truncation.


Jade | Level 19

You could use FIRSTOBS=2 on the INFILE statement.

Quartz | Level 8

It would be nice if the Filename statement supported the FIRSTOBS= option.  Then you would not need to data _null_ step.

(No offense!)


Calcite | Level 5

Fortunately these files are fairly small, just a couple of thousand records. This solution worked for me, thank you.

Quartz | Level 8

You did remember to remove

     datarow = 3;

didn't you?



Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1 like
  • 3 in conversation