Hi:
You might be able to use either PROC IMPORT or a DATA step program to read your data.
For example, let's say that you had the following CSV file stored in the location c:\temp\wronghdr.csv and it looked like:
[pre]
"name","v1","v2","v3"
"alan",11,12,13,14
"bob",21,22,,24
"carl",,32,33,34
"dave",41,42,43
"ed",51,52,53,54
[/pre]
Note how there are only 4 "headers" or variable names on line 1, but there are sometimes 5 data items on a line. Note also, how the data starts on line 2; and how at least 2 of the rows have values for all 5 columns, but some of the rows do NOT have values for all 5 columns.
If you did use PROC IMPORT to read the above file, one possible code method would be:
[pre]
proc import datafile="C:\temp\wronghdr.csv"
out=work.diffexamp
dbms=csv
replace;
datarow=2;
getnames=no;
run;
[/pre]
and the output would be:
[pre]
what happens with proc import
Obs VAR1 VAR2 VAR3 VAR4 VAR5
1 alan 11 12 13 14
2 bob 21 22 . 24
3 carl . 32 33 34
4 dave 41 42 43 .
5 ed 51 52 53 54
[/pre]
But, what if you REALLY want the NAME column to be NAME and not VAR1 -- you can see how PROC IMPORT names the variables when you skip over line 1.
For the most control over naming variables, especially in a tricky situation like yours, DATA step program code does give you the most control.
SAS has 4 different ways to read "flat files" or "text files" into a SAS dataset -- using DATA step program code. The code methods all involve the INPUT statement and if you look in the documentation for a topic entitled, "Statements: INPUT Statement", you will see a description of how to use each type:
Column Input
List Input
Formatted Input
Named Input
You can use whatever variable names you want, if you use an INPUT statement. In addition to using only one INPUT method or another, you can also mix different types of INPUT statements in the same program. If you write your own program, you can skip over line 1 (presumably the one with the headers), so it won't matter that the data has 22 headers on line 1, but 23 data fields, because in the INPUT statement, you get to name the variables/columns yourself, so if you KNOW that there are 23 data fields, you can list 23 variable names on your INPUT statement. Then if a single row does not have all 23 variables listed, you can use MISSOVER or TRUNCOVER (whichever is appropriate to your type of INPUT statement) to set the variable values to missing.
A SAS DATA step program to skip over line 1 and start looking for the first observation on line 2 in order to read the above data file and use variable names of your own choosing would be:
[pre]
data My_Col_Names;
infile 'c:\temp\wronghdr.csv' missover dsd firstobs=2;
input name $ var1 var2 var3 var4;
run;
proc print data=My_Col_Names;
title 'Correct column names no matter what was in line 1';
run;
[/pre]
and the result of the PROC PRINT would look like (note how the variable names from the INPUT statement were used, since line 1 was skipped over -- using the FIRSTOBS=2 option):
[pre]
Correct column names no matter what was in line 1
Obs name var1 var2 var3 var4
1 alan 11 12 13 14
2 bob 21 22 . 24
3 carl . 32 33 34
4 dave 41 42 43 .
5 ed 51 52 53 54
[/pre]
Your data may not look like what's above in the example of "wronghdr.csv", but in SAS there is usually a way to read just about ANY kind of file. You may not be able to use the EG automated wizards, but with code, you can read almost any text file into SAS format.
So, this is a perfect example of how you could get absolutely on-target help from Tech Support. They could take a look at your data file (if you sent them a sample) and make recommendations about the most appropriate form of INPUT statement to use.
cynthia