BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Syntas_error
Quartz | Level 8

From a practice exam:

-----------

The dataset Cars contains observations listing hte Make, Model and Country of Origin of 300+ vehicles. Consider the SAS code below:

 

 

data_null_;

attrib Make length=$15 Label="Make Name";

declare hash Makelist(dataest:'cars', ordered:'yes');

Makelist.definekey('Make');

Makelist.definedone();

rc=Makelist.output(dataset: 'Manufacturer');

run;

 

 

What is the result of running this program?

 

A) The manufacturer dataset contains unique values of Make in ascending order

B) The manufacturer Dataset contains unique values of Make in the original order as the input data.

C) The manufacturer Dataset contains a copy of the Cars dataset in order

D) The manufacturer Dataset contains a single observation as the data step iterates only once. 

 

I answered C but the correct answer is A. Does this then mean that the definekey statement enforces uniqueness on those variable values, similarly to the PRIMARY KEY constraint? 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Yes, the correct answer is A. 

 

First of all, only the Make variable is read into the hash object. Therefore, the manufacturer data set can not contain a copy of the Cars data set.

 

Secondly, when the Duplicate Argument Tag is not specified with the value 'Y', only the first value for each unique value of Make is read into the hash object. If you specified the code like below, all the values of Make (including duplicates) will be read into the hash object and consequently a part of the manufacturer data set

 

data _null_;

attrib Make length=$15 Label="Make Name";

declare hash Makelist(dataset:'sashelp.cars', multidata:'Y', ordered:'yes');

Makelist.definekey('Make');

Makelist.definedone();

rc=Makelist.output(dataset: 'Manufacturer');

run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Yes, the correct answer is A. 

 

First of all, only the Make variable is read into the hash object. Therefore, the manufacturer data set can not contain a copy of the Cars data set.

 

Secondly, when the Duplicate Argument Tag is not specified with the value 'Y', only the first value for each unique value of Make is read into the hash object. If you specified the code like below, all the values of Make (including duplicates) will be read into the hash object and consequently a part of the manufacturer data set

 

data _null_;

attrib Make length=$15 Label="Make Name";

declare hash Makelist(dataset:'sashelp.cars', multidata:'Y', ordered:'yes');

Makelist.definekey('Make');

Makelist.definedone();

rc=Makelist.output(dataset: 'Manufacturer');

run;
FreelanceReinh
Jade | Level 19

Hi @Syntas_error,


@Syntas_error wrote:

Does this then mean that the definekey statement enforces uniqueness on those variable values, similarly to the PRIMARY KEY constraint? 


No, it is the default multidata:'no' argument tag (in the parentheses after "Makelist" in the DECLARE statement) that makes Makelist a hash object with unique keys (which are then specified with the DEFINEKEY method).

 

(Also, note the typo in "dataest".)

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 411 views
  • 2 likes
  • 3 in conversation