user1069029
user1069029

Reputation: 11

junk values in a row( sas)

I have my data in a .txt file which is comma separated. I am writing a regular infile statements to import that file into a sas dataset. The data is some 2.5 million rows. However in the 37314th row and many more rows I have junk values. SAS is importing rows only a row above the junk value rows and therefore I am not getting a dataset with all 2.5 million rows but with 37314 rows. I want to write a code which while writing this infile takes care of these junk rows and either doesnt take them or deletes them. All in all, I need all the 2.5 million rows which I am not able to get because of in between junk rows.

any help would be appreciated.

Upvotes: 1

Views: 455

Answers (2)

Jay Corbett
Jay Corbett

Reputation: 28411

You can read the whole line into the input buffer using just an

 Input; 

statement. Then you can parse the fields individually using the

_infile_

variable.

Example:

data _null_;
 infile datalines firstobs=2;
 input;
  city = scan(_infile_, 1, ' ');
  char_min = scan(_infile_, 3, ' ');
  char_min = substr(char_min, 2, length(char_min)-2);
  minutes = input(char_min, BEST12.);
 put city= minutes=;
 datalines;
  City Number Minutes Charge
  Jackson 415-555-2384 <25> <2.45>
  Jefferson 813-555-2356 <15> <1.62>
  Joliet 913-555-3223 <65> <10.32>
  ;
run;

Working with Data in the Input Buffer.

Upvotes: 4

Robert Penridge
Robert Penridge

Reputation: 8513

You can also use the ? and ?? modifiers for the input statement to 'ignore' any problem rows.

Here's the link to the doc. Look under the heading "Format Modifiers for Error Reporting".

An example:

data x;
  format my_num best.;
  input my_num ?? ;

  **
  ** POSSIBLE ERROR HANDLING HERE:
  *;
  if my_num ne . then do;
    output;
  end;

datalines;
a
;
run;

Upvotes: 2

Related Questions