BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Nipun22
Fluorite | Level 6

Given the SAS data set SASDATA TWO:
SASDATA TWO
XY
- -

- - 
The following SAS program is submitted:


data sasuser.one two sasdata.three;
set sasdata two;
if x = 5 then output sasuser.one;
else output sasdata two;
run;

 

What is the result?

A. data set SASUSER.ONE has 5 observations
data set SASUSER. TWO has 5 observations
data set WORK. OTHER has 3 observations
B. data set SASUSER.ONE has 2 observations
data set SASUSER. TWO has 2 observations
data set WORK.OTHER has 1 observations
C. data set SASUSER.ONE has 2 observations
data set SASUSER. TWO has 2 observations
data set WORK.OTHER has 5 observations
D. No data sets are output.
The DATA step fails execution due to syntax errors.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

I would think in general without knowing what the input (or inputs) are then option D is going to be the only one you can be certain is the answer.  The other answers depend on what is in the input data.

 

Let's go through them one by one:

 

A. data set SASUSER.ONE has 5 observations, data set SASUSER. TWO has 5 observations, 
data set WORK. OTHER has 3 observations

For that to happen the data statement would need to be:

data sasuser.one sasuser.two other ;

So that there are 3 output datasets.  And the OUTPUT statements would need to either not mention any datasets (so that the observations is written to all of them) or only lists one or more of those datasets listed in the DATA statement.  So A is impossible given the OUTPUT statements even if the DATA statement was fixed.

 

B. data set SASUSER.ONE has 2 observations, data set SASUSER. TWO has 2 observations, data set WORK.OTHER has 1 observations

This seems to have the same problem.  


C. data set SASUSER.ONE has 2 observations, data set SASUSER. TWO has 2 observations, data set WORK.OTHER has 5 observations

This seems to have the same problem.  


D. No data sets are output. The DATA step fails execution due to syntax errors.

This one is true because the dataset names listed on the OUTPUT statements do not match the dataset names listed on the DATA statement.  Which is a syntax error and will cause the data step to not run.

 

View solution in original post

17 REPLIES 17
PaigeMiller
Diamond | Level 26

@Nipun22 wrote:

Given the SAS data set SASDATA TWO:


Invalid name for a data set, it cannot have a space in it. So ERROR right there. Or is that just a typo? Questions like this cannot have typos or you get syntax errors that weren't intended by the questioner, and we can't give a meaningful answer.

 

But please follow these instructions to share the data set with us (and no other way is acceptable).

 

If you want to know what SAS will do, run the code yourself, don't ask us, SAS will tell you definitively what happens.

--
Paige Miller
Tom
Super User Tom
Super User

As shown that code cannot run.

First because the two input datasets, WORK.SASDATA and WORK.TWO do not exist.

Second because the dataset WORK.SASDATA listed on the OUTPUT statement is not listed on the DATA statement.

1    data sasuser.one two sasdata.three;
2    set sasdata two;
ERROR: File WORK.SASDATA.DATA does not exist.
ERROR: File WORK.TWO.DATA does not exist.
3    if x = 5 then output sasuser.one;
4    else output sasdata two;
                 -------
                 455
ERROR 455-185: Data set was not specified on the DATA statement.

5    run;

ERROR: Libref SASDATA is not assigned.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set SASUSER.ONE may be incomplete.  When this step was stopped there were 0 observations and 1 variables.
WARNING: Data set SASUSER.ONE was not replaced because this step was stopped.
WARNING: The data set WORK.TWO may be incomplete.  When this step was stopped there were 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.95 seconds
      cpu time            0.01 seconds

 

Nipun22
Fluorite | Level 6

that's the thing question has to be solved without the input dataset. 

Quentin
Super User

In an exam they may ask you to solve the question without input dataset. But for learning purposes, you can create an input dataset that matches the question, and run the code from the question, and explore the results.  And try different data and code than is in the question, to see how stuff works.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Nipun22
Fluorite | Level 6

yes exactly i found this question on a website and can be a SAS Certification question

Nipun22_0-1718131440255.png

 

PaigeMiller
Diamond | Level 26

Ok, then the problem was so poorly stated by whoever made it up, that the only logical answer is D, the data step fails to execute (as explained by @Tom ).

--
Paige Miller
Nipun22
Fluorite | Level 6
what's your suggestions then? how should i prepare? and what if i find doubts in the online dumps?
Kurt_Bremser
Super User

When you have questions about specific points, bring them here.

Hint: there might be a reason why good preparations are not free (as in beer).

Creating a bunch of good and valid exam questions takes work. The one you showed here is simply crap. From where did you get it?

ballardw
Super User

The very first statement on that "page" or whatever that image comes from is just plain wrong.

It says "Given the data set SASDATA TWO"

That is an invalid name for a data set. The name could be SASDATATWO, SASDATA_TWO or even "SASDATA TWO"N but not as presented. And that same error is repeated in multiple places.

 

With that introduction I would say that the source of this question is unreliable and would not trust the answers for any question as the foundation information they are presenting is wrong.

I have to assume that your image is as presented. If the space appeared in only one place I might believe it is a typo but there is absolutely not way that code could write any observations to SASUSER.TWO as the exact characters SASUSER.TWO do not appear anywhere in the shown code.

 


@Nipun22 wrote:

yes exactly i found this question on a website and can be a SAS Certification question

Nipun22_0-1718131440255.png

 


 

PaigeMiller
Diamond | Level 26

Same question was asked 9 years ago in the SAS communities.

https://communities.sas.com/t5/SAS-Programming/sas-base-question/td-p/237111

 

And here's the same question on Flash Cards (but with different data)

https://quizlet.com/413354973/all-sas-questions-216-flash-cards/

 

 

--
Paige Miller
Nipun22
Fluorite | Level 6

how did you find this?

by searching the content of the questions?

ballardw
Super User

@Nipun22 wrote:

how did you find this?

by searching the content of the questions?


Google "Given the SAS data set SASDATA TWO:"

And there are dozens of places that someone (or a bunch of bots) have copied the exact same stuff.

Tom
Super User Tom
Super User

I would think in general without knowing what the input (or inputs) are then option D is going to be the only one you can be certain is the answer.  The other answers depend on what is in the input data.

 

Let's go through them one by one:

 

A. data set SASUSER.ONE has 5 observations, data set SASUSER. TWO has 5 observations, 
data set WORK. OTHER has 3 observations

For that to happen the data statement would need to be:

data sasuser.one sasuser.two other ;

So that there are 3 output datasets.  And the OUTPUT statements would need to either not mention any datasets (so that the observations is written to all of them) or only lists one or more of those datasets listed in the DATA statement.  So A is impossible given the OUTPUT statements even if the DATA statement was fixed.

 

B. data set SASUSER.ONE has 2 observations, data set SASUSER. TWO has 2 observations, data set WORK.OTHER has 1 observations

This seems to have the same problem.  


C. data set SASUSER.ONE has 2 observations, data set SASUSER. TWO has 2 observations, data set WORK.OTHER has 5 observations

This seems to have the same problem.  


D. No data sets are output. The DATA step fails execution due to syntax errors.

This one is true because the dataset names listed on the OUTPUT statements do not match the dataset names listed on the DATA statement.  Which is a syntax error and will cause the data step to not run.

 

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!
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
  • 17 replies
  • 755 views
  • 8 likes
  • 6 in conversation