Proc import just isn't going to do that very well if at all. You may have problems with variable types for the values of your header vars.
A data step will read headers directly with care. Example:
data example;
infile datalines dlm=',' missover;
informat HeaderVar1 HeaderVar2 $15. var1 $5. var2 f5.;
informat BodyVar1 f8. BodyVar2 f8. BodyVar3 $10. BodyVar4 f1. BodyVar5 $1.;
retain HeaderVar1 var1 HeaderVar2 var2 ;
retain indata 0;
if not(indata) then do;
input HeaderVar1 var1
/ HeaderVar2 var2
/
/
/ @;
indata=1;
end;
input BodyVar1 BodyVar2 BodyVar3 BodyVar4 BodyVar5; drop indata;
output;
datalines;
HeaderVar1,ABCD
HeaderVar2,43727
BodyVar1,BodyVar2,BodyVar3,BodyVar4,BodyVar5
123456,12345,TypeX,1,A
789012,12345,TypeY,2,B
;
This uses a comma delimited section of data lines to emulate the CSV file.
The principal is the same with more or fewer "header" lines.
The input statement with the / indicates continue reading on the next line for the current record. My example only includes two header rows, the blank row shown in your example and then the body variables header row. The two / without variables read the blank row and the header row (into nothing), the last / @ advances the input pointer to the start of the data. Note the check to see if we have actually read the file headers yet. The last bit after the / @ sets that check variable to True (1). The retain keeps the header variables and the indata check variable.
It wasn't clear exactly which "header" you actually wanted, so I kept all of them. You could drop the unwanted ones along with the indata variable.
After you have read each of the files then append them if needed.
Note that If these files are actually extremely similar except for the header block values there are ways to read multiple files and execute the header read when the external file being read changes.
Have you had any issues with the values of variables not aligning with your "cut and paste" with proc import? Each file that you run proc import on makes the procedure execute a separate set of "guesses" as to the variable types and you can run into problems letting the proc guess your variable types or lengths of character variables.
... View more