Help using Base SAS procedures

Base SAS certification exam question

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Base SAS certification exam question

Hi, Could anyone help me understand the logic behind the following question, before giving me the answer?

Given the SAS data set WORK.INPUT:

Var1     Var2 
 A        one
A        two
 B        three
 C        four
 A        five 

The following SAS program is submitted:

data WORK.ONE WORK.TWO; 
set WORK.INPUT; 
if Var1='A' then output WORK.ONE; 
output;
 run; 

How many observations will be in data set WORK.ONE?


Accepted Solutions
Solution
‎02-08-2017 07:44 AM
Respected Advisor
Posts: 4,606

Re: Base SAS certification exam question

The DATA statement announces that two datasets will be produced in the WORK library : ONE and TWO.

the OUTPUT WORK.ONE statement outputs Var1 and Var2 to dataset ONE, but only when Var1='A'

the OUTPUT statement outputs Var1 and Var2 to both datasets, whatever the value of Var1.

...

Do the counting Smiley Happy

PG

PG

View solution in original post


All Replies
Solution
‎02-08-2017 07:44 AM
Respected Advisor
Posts: 4,606

Re: Base SAS certification exam question

The DATA statement announces that two datasets will be produced in the WORK library : ONE and TWO.

the OUTPUT WORK.ONE statement outputs Var1 and Var2 to dataset ONE, but only when Var1='A'

the OUTPUT statement outputs Var1 and Var2 to both datasets, whatever the value of Var1.

...

Do the counting Smiley Happy

PG

PG
SAS Super FREQ
Posts: 8,681

Re: Base SAS certification exam question

Hi:

  I agree with PGStats... do the counting...or write the program and run the program. Equally important for understanding how the logic works, after you figure out how many obs are in WORK.ONE, try to figure out how many obs will be in WORK.TWO, then try to figure out WHY the counts are different. As a help, here's the code that makes the dataset WORK.INPUT.

  Then you should be able to code and test the rest.

cynthia

data work.input;

  infile datalines;

  input var1 $ var2 $;

return;

datalines;

A        one

A        two

B        three

C        four

A        five

;

run;

Occasional Contributor
Posts: 9

Re: Base SAS certification exam question

Thanks, PGStats & Cynthia.

Here's another one:

The following SAS program is submitted:

data gt100;

set airplanes(keep = type mpg load);

load = mpg * 150;

run;

The program fails to execute due to syntax errors.

What is the cause of the syntax error?

A. MPG is not a numeric variable.

B. LOAD is not a variable in the data set GT100.

C. LOAD is not variable in the data set AIRPLANES.

D. LOAD must be defined prior to the SET statement.

Thanks in advance,Smiley Happy

SAS Super FREQ
Posts: 8,681

Re: Base SAS certification exam question

Hi:

  Nobody from the forum is going to be in the exam with you. Does the test question show you what variables are in WORK.AIRPLANES? You should be able to figure this one out, too.

cynthia

Occasional Contributor
Posts: 9

Re: Base SAS certification exam question

Cynthia,

I am cracking a list of sample questions and cross-checking reliability of solutions given on the website. I have my answers with me but some of the online answers seem to be wrong.

Thanks

Contributor
Posts: 43

Re: Base SAS certification exam question

If you have no information as to what variables are there in work.airplanes, the most probable answer can be option C  I guess. Because, The keep= option tries to access load variable to be used in later statements since it happened to be in SET statement. So, if load variable is not already defined in the airplanes dataset, the program would stop during execution.

Super User
Super User
Posts: 6,137

Re: Base SAS certification exam question

Looks like these questions are like those on most standardized tests, you should pick the BEST answer. Using the Sherlock Holmes method helps (if you eliminate the impossible ...)

That is don't get too nit-picky.

In this case you can eliminate three of the answers as being clearly wrong.

A Would just cause SAS to automatically convert characters values to numeric values.

B Is just nonsense because this data step is defining the data set GT100.

D Is very poorly worded as what do they mean by defining LOAD in the context of this simple data step?  The most normal meaning is say that they mean you should have defined it via a LENGTH or ATTRIB statement before referencing it in the KEEP= option of the SET statement?  But no matter how you interpret the meaning of this choice SAS does NOT require you to pre-define variables.

So you are left with C as the BEST answer.  That one is only wrong if you know that the option DKRICOND is set to WARN instead of ERROR.

New Contributor
Posts: 4

Re: Base SAS certification exam question

[ Edited ]

LOAD is not a variable in the data set GT100. Base SAS Certification Questions and answers can help me crack the exam

Occasional Contributor
Posts: 9

Re: Base SAS certification exam question

Cynthia,


I am not sure if the code that you've given above would yield the same results as the code given in my original post.


My question says ' how many observations will be data set WORK.ONE? And if I run the count(as suggested by PGStats) then it is 8 observations of Var A that would go into WORK.ONE.

On the other hand,I did run the code that you gave, and what the DATALINES statement did was simply produced the same results as given in the code and total number of observation that the LOG gave were 5. So different results! thanks , anyways!


Gavy

SAS Super FREQ
Posts: 8,681

Re: Base SAS certification exam question

Gary:

  My program will ONLY create WORK.INPUT. You would have needed to type in the *REST* of the program yourself. I said I was going to get you started. Clearly, since you already cut and pasted the question part of the program (with work.one and work.two), I didn't think I needed to retype that portion.

  So you are correct, that WORK.INPUT has 5 observations. That is "given" in the statement of the problem. If you had typed and run the *REST* of the program you would have been able to verify your counting, as shown in the attached log, that WORK.ONE has 8 obs and WORK.TWO has 5 obs. WORK.ONE has the "extra" obs because of the "extra" output in the IF statement.

cynthia

Attachment
SAS Super FREQ
Posts: 8,681

Re: Base SAS certification exam question

Hi,

  IF (and it 's a big IF) any of the questions were wrong, they would be corrected immediately. But I am not aware of any of the sample questions being wrong. If you think the answer to a question is wrong, then write and run a program that shows it is wrong. You can send your program code and your log to certification@sas.com to report a possible problem with the question/answer.

  I think it is safe to assume that the posted answers are correct. If you think an answer is wrong, then you need to figure out WHY or HOW the posted answer could be right and what about your approach led you to a different answer.

cynthia

New Contributor
Posts: 3

Re: Base SAS certification exam question

It would write 8 obs in work.one dataset.

First output statement would write 3 obs (where var1 =''A' and second output statement would write each of the obs's to both the output datasets.

thus total obs written to work.one dataset = 3+5 =8

N/A
Posts: 1

Re: Base SAS certification exam question

8

New Contributor
Posts: 2

Re: Base SAS certification exam question

Answer is 8.

When assigned as OUTPUT in this program both in ONE & TWO include whatever data set is in INPUT. So both will be included 5 observations.

After running IF statement it includes 3 more observations to ONE as per the condition, So ONE contain 8 observation.

If you execute without OUTPUT then answer will be 3.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 31 replies
  • 14645 views
  • 4 likes
  • 11 in conversation