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

Another practice exam question:

 

-------------------------

The dataset Cars it not sorted, but is grouped by make. 

data dups uniquedata(index=(make/unique));

set cars (keep=make);

by make notsorted;

if first.make then output uniquedata;

else output dups;

run;

When you compile and execute the program above, what is the result?

 

A) Uniquedata contains a distinct list of Make in sequenced order. 

B)  Uniquedata contains a distinct list of Make but not necessarily in sequenced order

C)  Uniquedata contains a distinct list of Make but not necessarily in sequenced order, the index was built. 

D) The dataset DUPS is also indexed on Make.

--------------------

I answered C, since i couldn't find anything wrong with the code, but the answer is B. Is there any reason this index couldn't

be created?

 

Does the notsorted option somehow cancel the index?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Looks like you are right to me.

Try it.

data dups uniquedata(index=(make/unique));
  set sashelp.cars (keep=make);
  by make notsorted;
  if first.make then output uniquedata;
  else output dups;
run;

proc contents data=uniquedata; run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Looks like you are right to me.

Try it.

data dups uniquedata(index=(make/unique));
  set sashelp.cars (keep=make);
  by make notsorted;
  if first.make then output uniquedata;
  else output dups;
run;

proc contents data=uniquedata; run;
Tom
Super User Tom
Super User

Actually B is right when the same value of MAKE appears in mulitple groups.

Here is an example dataset that is NOT sorted, but is Grouped.

However it contains more than one grouping for the same value of MAKE.

data cars;
  input make $10.;
cards;
AUDI
AUDI
BMW
BMW
AUDI
VW
;
153   data dups uniquedata(index=(make/unique));
154     set cars (keep=make);
155     by make notsorted;
156     if first.make then output uniquedata;
157     else output dups;
158   run;

NOTE: There were 6 observations read from the data set WORK.CARS.
NOTE: The data set WORK.DUPS has 2 observations and 1 variables.
NOTE: The data set WORK.UNIQUEDATA has 4 observations and 1 variables.
ERROR: Duplicate values not allowed on index make for file UNIQUEDATA.
ERROR: Index creation failed for one or more indexes.

 

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