Processing Selected Raw Data Records Using IF Statements - SAS Programming

In cases where you only want to process selected records from a raw data file, you can make your programs more efficient by first reading only the variable(s) necessary to make the decision about whether or not you want to include the current record. The following example illustrates this concept:

Example – INEFFICIENT

DATA SUBSET;
INFILE 'input_file_spec';
INPUT @1 ID 3.
@5 GENDER $1,
€6 (Q1-Q10) ($1.);
IF GENDER='M';
RUN;

A better approach is to avoid reading all the variables into the PDV unless you plan to output that observation to the data set being created.The following program does just that.

Example – EFFICIENT

DATA SUBSET;
INFILE 'input_file_spec*;
INPUT @5 GENDER $1. @;
IF GENDER='M';
INPUT @l ID 3.
@6 (Q1-Q10) ($1.);
RUN;

Use the trailing to "hold the line" so that you can test the value of GENDER with a subsetting IF statement.If the value is not 'M'you can avoid the unnecessary I/O involved in reading all the other variables when gender is not an'M'.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics