## SAS multiple choice efficiency question

Solved
Occasional Contributor
Posts: 8

# SAS multiple choice efficiency question

[ Edited ]

Key says answer is option A, But according to my knowledge its for range of character variables so( Option D).

Thanks

Given a SAS data set with the following characteristics:
200 million observations
300 variables
Compressed
Resides on a network location
A SAS DATA Step program is written that will retrieve 20% of the data using a search based on a range of a character variable.
Which type of statement is the best choice to minimize computer resource utilization when subsetting this data?
A. KEEP/DROP
B. WHERE
C. CASE
D. IF/THEN/ELSE

Accepted Solutions
Solution
‎03-23-2018 01:29 AM
Super User
Posts: 2,518

## Re: SAS multiple choice efficiency question

I agree with @Reeza.

Supposing the question means what it seems to imply, the answer would be

where VAR between 'A' and 'B';

All Replies
Super User
Posts: 24,028

## Re: Base SAS

You need a new source for questions. You get what you pay for sometimes.

A is not correct and D would not be my guess.

Key says answer is option A, But according to my knowledge its for range of character variables so( Option D).

Thanks

Given a SAS data set with the following characteristics:
200 million observations
300 variables
Compressed
Resides on a network location
A SAS DATA Step program is written that will retrieve 20% of the data using a search based on a range of a character variable.
Which type of statement is the best choice to minimize computer resource utilization when subsetting this data?
A. KEEP/DROP
B. WHERE
C. CASE
D. IF/THEN/ELSE

Solution
‎03-23-2018 01:29 AM
Super User
Posts: 2,518

## Re: SAS multiple choice efficiency question

I agree with @Reeza.

Supposing the question means what it seems to imply, the answer would be

where VAR between 'A' and 'B';

Occasional Contributor
Posts: 8

## Re: SAS multiple choice efficiency question

I agree as where filters data before entering into PDV, So Where is more
efficient.

Thanks.
Super User
Posts: 2,518

## Re: SAS multiple choice efficiency question

Ha, that's the theory. If only things were that simple.

In fact WHERE clauses are a bit faster than IF tests when simple (equality or inequality) value validations are performed.

But they are slower when functions are used.

``````

16741  data TEST;
16742    do I=1 to 1e8;
16743      output;
16744    end;
16745  run;

16746  data _null_;
16747    set TEST;
16748    if I=1;
16749  run;

real time           5.21 seconds

16750  data _null_;
16751    set TEST;
16752    where I=1;
16753  run;

real time           4.73 seconds

16754  data _null_;
16755    set TEST;
16756    if round(I)=1;
16757  run;

real time           8.40 seconds

16758  data _null_;
16759    set TEST;
16760    where round(I)=1;
16761  run;
real time           16.07 seconds

``````

In this simple test on my PC, WHERE is 10% faster than IF for an equality validation, but 100% slower if a function is used.

I only uncovered these variations last year, and will have to update the third edition of my book.

It looks as if functions compiled as part of the data step are more efficient than functions that process the data buffer before the PDV is loaded.

☑ This topic is solved.