| Date: | Thu, 21 Jan 2010 20:01:31 -0500 |
| Reply-To: | Arthur Tabachneck <art297@NETSCAPE.NET> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Arthur Tabachneck <art297@NETSCAPE.NET> |
| Subject: | Re: Importing CSV, first row has column names |
|
The problem might simply be that there is a blank line at the start of
your csv file.
If that is the case, I don't know of an import option that can correct the
situation. One solution would be to simply read the file, rewrite it
excluding the first line, and then importing it.
For example:
/* Create a test csv file with a blank first line */
data _null_;
set SASHELP.CLASS;
file 'c:\class.csv' delimiter=',' DSD DROPOVER lrecl=32767;
format Name $8. ;
format Sex $1. ;
format Age best12. ;
format Height best12. ;
format Weight best12. ;
if _n_ = 1 then do; /* add extra row and then write column names */
put " ";
put
'Name'
','
'Sex'
','
'Age'
','
'Height'
','
'Weight'
;
end;
do;
put Name $ @;
put Sex $ @;
put Age @;
put Height @;
put Weight ;
;
end;
run;
/* Create a new csv file without a blank first line */
data _null_;
file "c:\temp.csv";
infile "c:\class.csv" truncover;
informat x $300.;
input x;
if _n_ gt 1 then put x;
run;
/* Import the file */
proc import datafile='k:\art\class.csv'
out=newfile dbms=csv replace;
getnames=yes;
run;
HTH,
Art
-------
On Thu, 21 Jan 2010 13:10:26 -0800, Sdlentertd <sdlentertd@GMAIL.COM>
wrote:
>When import csv file :
>
>proc import datafile='file.csv'
>out=newfile dbms=csv replace;
>getnames=yes;
>run;
>
>this happens: column names appear in Row 1 instead of actual column
>names (that are now Var1, etc...)..... how can I either import column
>names so they appear as column names, or rename first row (values)
>into column names
>Thank you
|