Doesn't really change the prescription for the algorithm to use to parse it.
You could try using the RANGE= statement in the PROC IMPORT code to limit the input to specific parts of the sheet.
Or if you can get them to make named ranges in the worksheet then your can reference those in the RANGE= statement.
Try this method.
%let infile=c:\downloads\Input Data.xls;
* Read entire file and ignore column names ;
proc import datafile="&infile" out=have replace dbms=xls ;
getnames=no;
run;
* Add ROW numbers ;
data have ;
row+1;
set have ;
run;
* Generate Y_MONTH and variable names from first three rows ;
proc transpose data=have(obs=3 drop=a b c d row) prefix=name out=names(drop=_label_) ;
var _all_;
run;
data names;
length _newname_ $32 Y_month $6 ;
set names ;
if name2 = 'US' then name2=' ';
if name3 = 'US' then name3=' ';
y_month=scan(name1,-1,' ~/')||scan(name1,-2,' ~/') ;
name1=scan(name1,1,' ~');
_newname_=translate(trim(coalescec(of name3-name1)),'____',' .~/');
run;
* Transpose the data lines ;
proc transpose data=have(firstobs=6 drop=a b c d) out=values(drop=_label_ where=(_name_ ne 'row'));
by row;
var _all_;
run;
* Combine with names, convert to numbers ;
proc sql noprint ;
create table values2 as
select a.row
, a._name_
, input(col1,comma32.) as col1
, b._newname_,b.y_month
from values a , names b
where a._name_ = b._name_
order by a.row,b.y_month
;
run;
* To force column order add extra row with names in order and missing ROW and Y_MONTH ;
data values3 ;
set names (drop=Y_month) values2;
run;
* Transpose ;
proc transpose data=values3 out=want (drop=_name_ where=(row ne .)) let;
by row y_month ;
id _newname_;
var col1 ;
run;
* Add back the first 4 columns ;
data want ;
merge have(firstobs=6 keep=row a b c d) want ;
by row ;
rename a=M_Type b=M_TYPE_DESC c=P_H_Desc d=MARKET_Type_Ind ;
run;
proc print; run;
Thanks everybody for help...
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.