Or you could use a tool that can guess how to read the file and take the names from somewhere other than the first line. Proc import file=goodcsv dbms=csv out=want replace Or you could make a copy of the CSV file without the extra lines and then you could use PROC IMPORT and it will be able to guess how to name the variables based on the header row. Restriction: A pathname for a file can have a maximum length of 201 characters. Select catx('=',nliteral(_name_),nliteral(col1)) The IMPORT procedure reads external data and writes the data to a SAS data set or to a CAS table if the CAS LIBNAME engine is used and a connection to the CAS server is active. Proc transpose data=headers(obs=1) out=names Proc import file=badcsv dbms=csv out=headers replace proc import file=badcsv dbms=csv out=nonames replace You can even use PROC IMPORT to read the second line to get strings to use as the names. Or you can read from the third row while telling PROC IMPORT not to try to get names from the file. The easiest is to skip the PROC IMPORT and just write your own data step to read the file: data want SAS and character data: background: SAS stores character values in a fixed length field. Here are some ways to deal with such a file. data step and default length of character variables. If you have such a "bad" CSV file then you cannot use PROC IMPORT to read it directly because PROC IMPORT will always use the FIRST line as the source for guessing how to name the variables, no matter where you tell it to start reading the datalines. If _n_=1 then put 'This is an extra line' Proc export data=sashelp.class dbms=csv file=csv replace Let's make an example "bad" csv file by first dumping SASHELP.CLASS to a CSV file and then copying the good CSV file to a new file with an extra row at the top. These strings are usually used as the names for the variables.) (Note: The header row is one with text strings instead of variable values. Assuming you actually have a CSV file (which is form of a delimited text file) but that the problem is that your file has an extra line before the header row.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |