BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aman4SAS
Obsidian | Level 7

data test;

infile datalines missover;

input x y$ z;

datalines;

34     aman 56

56 vikash 34

34   aman 56

56     vikash 34

34   aman

56              34

          aman 56

56   vikash 34

34   aman 56

56 vikash

34      56

56 vikas

;

run;

proc print; run;

please let me know how i can read records in correct format...

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Then try:

data test;

  infile datalines truncover;

  input x 1-2;

  _infile_=substr(_infile_,3);

  y=scan(_infile_,1);

  if not anyalpha(y) then do;

    call missing(y);

    z=input(scan(_infile_,1),8.);

  end;

  else z=input(scan(_infile_,2),8.);

  datalines;

34     aman 56

56 vikash               34

34   aman 56

56     vikash 34

34   aman

56              34

          aman       56

56   vikash 34

34   aman 56

56 vikash

34      56

56 vikas

;

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

At least for your example, the following would work:

data test;

  infile datalines truncover;

  input @;

  _infile_=tranwrd(_infile_,'        ',' ');

  _infile_=tranwrd(_infile_,'      ',' . ');

  input x 1-2 y $ z;

  datalines;

34     aman 56

56 vikash 34

34   aman 56

56     vikash 34

34   aman

56              34

          aman 56

56   vikash 34

34   aman 56

56 vikash

34      56

56 vikas

;

Aman4SAS
Obsidian | Level 7

Thank you very much for your kind help.

sir i would like to add one thing that your ans is suitable for only this sample data in exact this format. but  if i will change place of any field value(means adding one or more space in between) so it will give wrong ans. which is possible to come in complete population.

i tried something but it is not working in name field.

data test;

  infile datalines truncover dlm=",";

  input @;

  _infile_=tranwrd(_infile_,' ',",");

  input x 1-2 y $ z;

  datalines;

34     aman 56

56 vikash               34

34   aman 56

56     vikash 34

34   aman

56              34

          aman       56

56   vikash 34

34   aman 56

56 vikash

34      56

56 vikas

;

run;

Kindly suggest me ....

art297
Opal | Level 21

Then try:

data test;

  infile datalines truncover;

  input x 1-2;

  _infile_=substr(_infile_,3);

  y=scan(_infile_,1);

  if not anyalpha(y) then do;

    call missing(y);

    z=input(scan(_infile_,1),8.);

  end;

  else z=input(scan(_infile_,2),8.);

  datalines;

34     aman 56

56 vikash               34

34   aman 56

56     vikash 34

34   aman

56              34

          aman       56

56   vikash 34

34   aman 56

56 vikash

34      56

56 vikas

;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 857 views
  • 3 likes
  • 2 in conversation