DATA Step, Macro, Functions and more

"Lost Card" stops process of reading in multiple files with infile filevar

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

"Lost Card" stops process of reading in multiple files with infile filevar

I am trying to read in data from all of the files from a particular directory.  My variable "allpath" specifies the location of each file.  I am starting to read each file at observation 18.  However, some files do not contain at least 18 lines.  What happens is that upon the first occurrence of a file with <18 lines, I receive a "NOTE: LOST CARD." statement and an error message, then the file read-in process stops.  I have all of the data read in up to that point output to jtest, but nothing beyond that.  I was on the verge of hardcoding to delete those records from "allpath", but I prefer to handle it automatically by having SAS either ignore those files, given the inadequate number of data lines or export a row of missing variables for those files.

 

QUESTION: How do I keep reading in additional files after having a file without data?

 

Thanks for your help!

shorine

 

Here is my code (dataset jabc1 contains all of the pathing to the files):

 

data jtest;
set jabc1;
format flagjet 3.;
do until(done);
  infile indummy filevar=allpath firstobs=18 obs=317 end=done;

    input @1 anyrec $4.;
    if done then flagjet=1;
    output;
end;
run;

 

Here is the error message from my log (there are approx 65 files to read in, so not all are being processed):


NOTE: LOST CARD.
subjid=1234 visit=1 task=ABC
allpath=D:\MYFOLDER\ABC_Subj1234_Visit1_Rep1.txt

flagjet=. done=1 anyrec= _ERROR_=1 _N_=27
NOTE: There were 27 observations read from the data set WORK.JABC1.
NOTE: The data set WORK.JTEST has 7204 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

An inadequate dataset looks like:

*************************************************************
2018-04-10 10:18:44 AM
Subject:1234
Visit:1

 

 

A good dataset looks like:

*************************************************************
2017-08-17 12:23:50 PM
Subject:4321
Visit:1

Criterion1: zz
Criterion2; d
Criterion3: w
-
-
-
-
-
-
-
-
-
-
1 d
2 f
3 d
4 c
5 e

... up to 300 records


Accepted Solutions
Solution
‎04-14-2018 01:01 AM
Super User
Super User
Posts: 8,093

Re: "Lost Card" stops process of reading in multiple files with infile filevar

Make sure to test the END= variable so that you do not read past the end of any file. Also add the TRUNCOVER option so that trying to read past the end of an individual line does not cause the INPUT statement to try to read another line.

data jtest;
  set jabc1;
  infile indummy filevar=allpath truncover obs=317 end=done;
  do _N_=1 to 17 while (not done);
    input; 
  end;
  do while(not done);
    input anyrec $4.;
    flagjet=done ;
    output;
  end;
run;

 

View solution in original post


All Replies
PROC Star
Posts: 2,350

Re: "Lost Card" stops process of reading in multiple files with infile filevar

Like this?

  infile INDUMMY filevar=ALLPATH obs=317 end=DONE pad;
  do until(DONE or RECNO=18);
    input @1 ANYREC : $4.;       
    RECNO+1;
  end;
  if RECNO=18 then do until(DONE);
    output;
    if DONE then FLAGJET=1;
    else input @1 ANYREC : $4.;
  end;

 

New Contributor
Posts: 3

Re: "Lost Card" stops process of reading in multiple files with infile filevar

I think that this code may work with some small tweaks, but I was not able to get it to work properly.
Solution
‎04-14-2018 01:01 AM
Super User
Super User
Posts: 8,093

Re: "Lost Card" stops process of reading in multiple files with infile filevar

Make sure to test the END= variable so that you do not read past the end of any file. Also add the TRUNCOVER option so that trying to read past the end of an individual line does not cause the INPUT statement to try to read another line.

data jtest;
  set jabc1;
  infile indummy filevar=allpath truncover obs=317 end=done;
  do _N_=1 to 17 while (not done);
    input; 
  end;
  do while(not done);
    input anyrec $4.;
    flagjet=done ;
    output;
  end;
run;

 
New Contributor
Posts: 3

Re: "Lost Card" stops process of reading in multiple files with infile filevar

This code worked. Thanks very much! shorine
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 129 views
  • 0 likes
  • 3 in conversation