BookmarkSubscribeRSS Feed
Sudtej
Calcite | Level 5

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.

2 REPLIES 2
LinusH
Tourmaline | Level 20

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
Reeza
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1661 views
  • 0 likes
  • 3 in conversation