BookmarkSubscribeRSS Feed
bogapraveen
Calcite | Level 5

Hi,

 

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

please give the code.

 

Thank you,

 

Regards,

Praveen

 

3 REPLIES 3
art297
Opal | Level 21

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

 

bogapraveen
Calcite | Level 5

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

Tom
Super User Tom
Super User

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
;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 808 views
  • 0 likes
  • 3 in conversation