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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

31 REPLIES 31
PGStats
Opal | Level 21

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
Cynthia_sas
SAS Super FREQ

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;

GavyK
Calcite | Level 5

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

Cynthia_sas
SAS Super FREQ

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

GavyK
Calcite | Level 5

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

JVarghese
Obsidian | Level 7

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.

Tom
Super User Tom
Super User

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.

HimanshuKumar
Fluorite | Level 6

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

GavyK
Calcite | Level 5

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

Cynthia_sas
SAS Super FREQ

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


complete_answer.png
Cynthia_sas
SAS Super FREQ

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

Vikesh
Fluorite | Level 6

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

KakaDa
Calcite | Level 5

8

SujataHiremath
Calcite | Level 5

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 31 replies
  • 22927 views
  • 12 likes
  • 11 in conversation