BookmarkSubscribeRSS Feed
Tom
Super User Tom
Super User

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.

Tom
Super User Tom
Super User

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;

pp2014
Fluorite | Level 6

Thanks everybody for help...

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 1511 views
  • 0 likes
  • 6 in conversation