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

Hi,

would anyone, I was curious about the question.  I think if the code had an 'else if' instead of just output then the code would separate the dataset, as I would presume this is what you would want to do 'normally'.

data work.one work.two;

set work.input;

if var1='A' then output work.one;

else output work.Two;

run;

my question would would there be a case that some one would use the original program?

marv

Cynthia_sas
SAS Super FREQ

Hi:

  That is one possible scenario, if the goal is to split the data based on the value of VAR1 so that ONLY the observations with VAR1=A are placed in WORK.ONE and the other obs are placed in WORK.TWO.

  However, the point of the question was not for the student to rewrite the question or recast it into a different question. The question gives the code. No matter how improbably you think the example is, the question has a point that is based on how SAS Syntax works. The question, based on the way the code was originally written, asks the student to figure out how many observations would be in WORK.ONE. The correct answer was 8. The question is designed to test whether the student understands how the explicit OUTPUT statement works. A frequent beginner mistake is failing to code the ELSE because they do NOT understand how the explicit OUTPUT statement works. And the consequences of not understanding how the explicit OUTPUT statement works is to get the "unexpected" number of observations in one or more than one of the output datasets. If you understand HOW the explicit OUTPUT statements works, then you will understand WHY the correct answer is 8, and so, you will always be able to answer a question like this correctly. The fact you understand that a well placed ELSE might help you out in this instance is great, but on the exam, you have to answer the question you are asked.

cynthia

bustergomez
Calcite | Level 5

Thanks Cynthia,

Makes sense, I've been studying for SAS certification and I agree, many of the question are the way you described.  It's extremely helpful just studying the material in this way as I get tons of 'Ah, that's how that works' moments when I encounter code that otherwise would not make sense.

Also just wanted to say Cynthia you do a great job answering all of our SAS questions, you must be on your millionth question!

I don't know how you do it.

Marv

SujataHiremath
Calcite | Level 5

Hi,

Right now you got resolved current question but actual question in SAS BASE CERTIFICATION will be more tougher. Actually A00-201 series dumps will available but examination will series A00-211. Don't get confused. After better preparation only go for examination.

Sujata 

himzi_SAS
Calcite | Level 5

Hi Cynthia,

I have been following your explanations and it helped me a lot. I am going to write my SAS base exam very soon but have some doubts. So if you can clear one of them that would help me a lot. see the following question:

data allobs;

set sasdata.banks;

capitaI=0;

do year = 2000 to 2020 by 5;

capital + ((capital+2000) * rate);

output;

end;

run;

How many observations will the ALLOBS data set contain?

A. 5

B. 15

C. 20

D. 25

I know the answer but want to know the exact explanation.

Thanks,

Tom
Super User Tom
Super User

You did not provide enough information to answer the question.  How many observations are in the input data set?

himzi_SAS
Calcite | Level 5

I am sorry for that... here is is the complete question

The SASDATA.BANKS data set has five observations when the following SAS program is

submitted;

libname sasdata ‘SAS-data-library’;

data allobs;

set sasdata.banks;

capitaI=0;

do year = 2000 to 2020 by 5;

capital + ((capital+2000) * rate);

output;

end;

run;

How many observations will the ALLOBS data set contain?

A. 5

B. 15

C. 20

D. 25

Tom
Super User Tom
Super User

How many times will the DO loop execute?

Therefore how many times will the OUTPUT statement execute for each time through the data step?

How many times will the data step execute?

himzi_SAS
Calcite | Level 5

Acc to me  as mentioned in the question year= 2000-2020 by 5 ,

So therefore Do loop will execute for 4 times (2000-2005, 2005-2010, 2010-2015 and 2015-2020).

and as there are 5 observations in input data set so,

total observations = 4*5 = 20

Is It correct ?

Thanks,

Tom
Super User Tom
Super User

How many times will DO I=1 to 5 by 1 execute?

How about DO I=0 to 4 by 1 ?

himzi_SAS
Calcite | Level 5

both loops will run 5 times ..

even If we do not mention by 1,

by default they will run 5 times.

but I still dint get the Idea :smileyconfused:

Tom
Super User Tom
Super User

DO YEAR=2000 TO 2020 BY 5 ;

Will loop in this way.

  • Set YEAR=2000
    • Is it bigger than 2020 ? NO  execute the loop
  • Set YEAR=2000+5
    • Is it bigger than 2020 ? NO  execute the loop
  • Set YEAR=2005+5
    • Is it bigger than 2020? NO  execute the loop
  • Set YEAR=2010+5
    • Is it bigger than 2020? NO  execute the loop
  • Set YEAR=2015+5
    • Is it bigger than 2020? NO  execute the loop
  • Set YEAR= 2020+5
    • Is it bigger than 2020? YES stop

And this will happen for every observation read from the input.  So each observation will cause 5 OUTPUT statements to be executed.  So when input data set has 5 observations there will by 25 total observations written to the output data set.

himzi_SAS
Calcite | Level 5

Ok I got It,

The loop will run for the 5 times not 4, as we will also include 2020-2025 in loop.

So answer should be 5*5= 25

Is It correct ? Smiley Happy

Tom
Super User Tom
Super User

Yes. When YEAR=2020 the loop will execute.  DO I=START to END will execute the loop when I=END and stop when I > END.

himzi_SAS
Calcite | Level 5

Thank you very much Tom for the explanation!!

much appreciated Smiley Happy

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!
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
  • 23438 views
  • 12 likes
  • 11 in conversation