BookmarkSubscribeRSS Feed
cosmid
Lapis Lazuli | Level 10

Which of the following programs correctly reads the data set Orders and creates the data set FastOrdr?

a. data cert.fastordr(drop=ordrtime);

       set cert.orders(keep=product units price);

       if ordrtime<4;

       Total=units*price;

    run;

b. data cert.orders (drop=ordrtime);

       set cert.fastordr(keep=product units price);

       if ordrtime<4;

       Total=units*price;

    run;

c. data cert.fastordr(drop=ordrtime);

        set cert.orders(keep=product units price ordrtime);

        if ordrtime<4;

        Total=units*price;

     run;

d. none of the above

 

Correct Answer: a

 

Here's the explanation from the back of the book:

 

You specify the data set to be created in the DATA statement. The DROP=data set option prevents variables from being written to the data set. Because you use the variable OrdrTime when processing your data, you cannot drop OrdrTime in the SET statement. If you use the KEEP= option in the SET statement, then you must list OrdrTime as one of the variables to be kept.

 

My question is why isn't the correct answer c? And I don't think a is the correct answer.

6 REPLIES 6
ballardw
Super User

"Correct" depends on what the output is supposed to look like.

 

Answer A will create a variable ordrtime and set it too missing since it is not on the dataset option KEEP statement. It just doesn't have ordrtime in the output. Since ordrtime has the value missing it will always be true so all of the records form orders will appear in the output.

 

You don't show us what any of the values of ordrtime in the ORDERS set look like. If all of them are 4 or greater the output set would have zero observations.

 

If ordrtime has a range of values less than 4 and greater than 4 I might agree with you if the intent was to filter on the value of ordrtime.

 

Choices always involve knowing what the desired output should be. The question may be incomplete without actual data.

cosmid
Lapis Lazuli | Level 10

There is no value or output. That's everything there is for that question. I added the explanation from the book to the post. In the explanation, it even said because the variable OrdrTime was used for processing the data, it cannot be dropped in the SET statement.

ballardw
Super User

@cosmid wrote:

There is no value or output. That's everything there is for that question. I added the explanation from the book to the post. In the explanation, it even said because the variable OrdrTime was used for processing the data, it cannot be dropped in the SET statement.


When in doubt, create data and run the code:

data work.orders;
   input product $ units price ordrtime;
datalines;
A  27  43.99 1
B  16  18.88 5
C  1   199.99 2
;
run;

data work.fastordra(drop=ordrtime);
    set work.orders(keep=product units price);
    if ordrtime<4;
    Total=units*price;
run;

data work.fastordrc(drop=ordrtime);
    set work.orders(keep=product units price ordrtime);
    if ordrtime<4;
    Total=units*price;
run;

No errors, data is output to both the A and C versions.

The difference is how the ordrtime variable is treated. And as I say, what the output should look like.

 

Since both options create output the question requirement is incomplete. The question should indicate that only values where the existing ordrtime less than 4 should be calculated and in the output. The explanation is not consistent with the code for A, which makes me think that a previous document was updates moving the code choices around but leaving the answer key the same. It happens.

Astounding
PROC Star

You're right.

 

Sometimes printed quizzes are wrong.

 

Who composed the problem?

cosmid
Lapis Lazuli | Level 10

This is Question 9 from Chapter 9 from the book SAS Certification Prep Guide, Fifth Edition. So far, I'm disappointed in this book. I just added the explanation in the back of the book to this post. The explanation itself conflicts with the answer.

paulsonalec
Obsidian | Level 7

I realize I'm late to the party, but I had the same questions. There's no way that A is the correct answer! If we just 'keep=product units price' in the set statement, how do we subsequently limit to just cases where 'ordrtime<4'. I picked C as well

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1305 views
  • 1 like
  • 4 in conversation