Base SAS Certification Questions Series - Part 3

The Global SAS certification exam is administered by SAS and Pearson VUE together. There are 60-65 multiple choice questions in Base SAS certification exam and candidate must achieve 70% score to pass multiple choice questions in  110 minutes.

We had started a series of articles to help you prepare for this examination. Here comes the third one covering few more.


Q6. The Banks data set has six observations when the following SAS program is submitted; 

data Allobs;
set Banks;
capital=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. 25
D. 30


Answer of the question is highlighted.

Explanation: 

Here the source dataset "Banks" contains 6 observations and Do Loop will go in 5 iterations (2000, 2005, 2010, 2015, 2020) for each observation and thus creates a total of 30(6*5) observations.

For better explanation try following code. 

Data DS;
do n = 1 to 20 by 2;
square = n * n;
output;
end;
Run;

Here, the DS dataset will have two variable n and square with 10 observations.


Q7. The SAS data set BANKS is listed below:

Banks_Name         Rate
FirstCapital          0.0718
DirectBank          0.0721
VirtualDirect       0.0728

The following SAS program is submitted:

Data Newbank;
set banks;
do year = 1 to 4;
capital + 5000;
end;
Run;

Which one of the following represents how many observations and variables will exist in the SAS
data set NEWBANK?

A. 0 observations and 0 variables
B. 3 observations and 4 variables
C. 3 observations and 3 variables
D. 9 observations and 2 variables

Answer of the question is highlighted.

Explanation: 

The source dataset has three observation and due to looping statement, data step must go in
4 iterations for each of the three observations.
 However, output statement is missing and thus for each observation data set will hold only the observation of the last iteration.
New dataset Newbank will have 3 observation and 4 variables(Banks_Name, Rate,Year and Capital).

Q8. The following SAS program is submitted:

Data work.pieces;
do while (n lt 6);
n + 1; 
end;
run;

Which one of the following is the value of the variable N in the output data set?

A. 4
B. 5
C. 6
D. 7

Answer of the question is highlighted.

Explanation: 

DO WHILE statement executes a DO loop while the expression is true. In this case, Do while will iterate 6 times till N reaches 6 and without output statement N will hold only the value of the last iteration and that is 6.

For better explanation try following code with output statement. 
Data work.pieces;
do while (n lt 6);
n + 1; 
output;
end;
run;

Here, the DS dataset will have one variable N with 6 observations.


Q9. The following SAS program is submitted:

Data work.sales;
 do year = 1 to 5;
    do month = 1 to 12;
    x+ 1;
    output;
    end;
 end;
run;

Which one of the following represents how many observations are written to the WORK.SALES
data set?

A. 0
B. 1
C. 5
D. 60

Answer of the question is highlighted.

Explanation: 

Now we have a classic example of nested looping (loop inside a loop). First outer loop of year will go in 5 iterations. The second inner loop of month will go for 12 iterations for each of the 5 years thus making it total of 60 iterations and thus dataset will hold 60 observations.

Example 1: Try the above code without any output statement.

Data work.sales1;
 do year = 1 to 5;
    do month = 1 to 12;
    x+ 1;
    end;
 end;
run;

Here, There will be only one observation in the dataset WORK.SALES.


Example 2: Try the above code with two output statements.

Data work.sales2;
 do year = 1 to 5;
    do month = 1 to 12;
    x+ 1;
    output;
    end;
 output;
 end;
run;

Here, There will be 65 observation in the dataset WORK.SALES.



Enjoy reading our other articles and stay tuned with ...

Kindly do provide your feedback in the 'Comments' Section and share as much as possible.

No comments:

Post a Comment

Do provide us your feedback, it would help us serve your better.