turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- CPU Time to be Processed

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-15-2014 02:34 AM

Hi

The SAS data set TEMP has the following distribution of values for variable A:

A Frequency

1 500,000

2 500,000

6 7,000,000

8 3,000

Which one of the following SAS programs requires the least CPU time to be processed?

A. data new; set temp; if a = 8 then b = 'Small '; else if a in(1, 2) then b = 'Medium'; else if a = 6 then b = 'Large'; run;

B. data new; set temp; if a in (1, 2) then b = 'Medium'; else if a = 8 then b = 'Small'; else if a = 6 then b = 'Large'; run;

C. data new; set temp; if a = 6 then b = 'Large '; else if a in (1, 2) then b = 'Medium'; else if a = 8 then b = 'Small';run;

D. data new; set temp; if a = 6 then b = 'Large '; if a in (1, 2) then b = 'Small'; run;

Note: The above question is from Advance sas practice exam which i found online. i would like to know the correct answer and why?

Thank you.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-15-2014 08:38 AM

If SAS hits a TRUE, the rest of the if-then-else logic is not executed.

Therefore, one should organize the code, so that the most likely expression to be TRUE, is to be evaluated first.

Data never sleeps

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-15-2014 11:41 PM

C.

You should order your conditions in the order they occur in the data set, most frequent to less frequent. Also, if conditions are mutually exclusive use the if then is faster than multiple if as in D.