DATA Step, Macro, Functions and more

How to read data from the matrix

Reply
New Contributor
Posts: 2

How to read data from the matrix

Hi,

 

Please let me know how to read the attached data in the proper way.

please give the code.

 

Thank you,

 

Regards,

Praveen

 

PROC Star
Posts: 7,363

Re: How to read data from the matrix

I don't think there is one "proper" way. Here is one way that would work:

 

data  want (drop=_:);
  infile 'c:\art\ds.txt' firstobs=6;
  informat name $40.;
  input @;
  call scan(_infile_,-1,_position,_length);
  month=substr(_infile_,_position);
  _infile_=substr(_infile_,1,_position-1);
  input sales orderno name &;
run;

Art, CEO, AnalystFinder.com

 

New Contributor
Posts: 2

Re: How to read data from the matrix

Thank you for your reply, I am getting output what I expected.

Is there any shortcut code apart from this line, using  : @ type of input statements.

 

I am sorry, I could understand the following line. 

 

input @;
  call scan(_infile_,-1,_position,_length);
  month=substr(_infile_,_position);
  _infile_=substr(_infile_,1,_position-1);

 Thank you,

 

Regards,

Praveen

 

 

 

 

 

Regards,

Praveen

Super User
Super User
Posts: 6,500

Re: How to read data from the matrix

[ Edited ]

Depends on what you want. If you want to read them all into a single row then just read them all as names and move the last one into the month field.

data want;
  infile datalines truncover  ;
  length sales orderno 8 month $3 num 8;
  array name (10) $28 ;
  input sales orderno name1-name10 ;
  num =  dim(name) - cmiss(of name(*));
  month = name(num);
  name(num)=' ';
  num=num-1;
  format sales dollar9.;
datalines;
25000 2 raheem pasha shaik jan
30000 3 shaik shabeer pasha aug
45000 6 rama krishna oct
98000 5 gopal feb
;
Ask a Question
Discussion stats
  • 3 replies
  • 171 views
  • 0 likes
  • 3 in conversation