05-29-2014 06:03 PM
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:
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?
05-29-2014 07:06 PM
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 ;
if _N_ = 1 then return ;
put _infile_ ;
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..
05-29-2014 07:08 PM
Also, you probably will need to set LRECL= 9999 or some large number on the filename statements to avoid truncation.
05-29-2014 09:35 PM
It would be nice if the Filename statement supported the FIRSTOBS= option. Then you would not need to data _null_ step.
05-29-2014 11:23 PM
Fortunately these files are fairly small, just a couple of thousand records. This solution worked for me, thank you.