SAS A00-215 SAS 9.4 Programming Fundamentals Exam Practice Test

Page: 1 / 14
Total 78 questions
Question 1

Which assignment statement uses the SUBSTR function to extract the four-digit year from the value of date?

data days;

date="02Apr2019";

insert-statement-here

run;



Answer : A

In SAS, the SUBSTR function is used to extract a substring from a character string. The function syntax is SUBSTR(string, position, length), where:

string is the variable or string literal you want to extract the substring from.

position is the starting position of the substring within string.

position starts counting at 1 in SAS, not 0 as in some other languages.

length is the number of characters to extract.

For the value of date provided ('02Apr2019'), we want to extract the year, which is the four characters at the end of the string.

Here's how each option would work given the string:

A) year=substr(date, 7, 4); This starts at the 7th character of the string ('2019') and extracts 4 characters, which correctly represents the year.

B) year=substr(date, 4, 6); This starts at the 4th character ('Apr2019') and would extract 6 characters, which gives us 'Apr201', not just the year.

C) year=substr(date, 6, 4); This starts at the 6th character ('r2019') and would extract 4 characters, resulting in 'r201', which is not correct.

D) year=substr(date, 4, 7); This starts at the 4th character and would extract 7 characters, resulting in 'Apr2019', which is the whole string from the 4th character to the end, not just the year.

The correct answer is A, as it extracts the four-digit year from the end of the string.


The SAS documentation on the SUBSTR function, which details how to use it for extracting parts of strings.

SAS programming tutorials that often provide examples of common functions like SUBSTR for string manipulation

Question 2

What happens when you submit the code shown below?

data table1 table2;

set sashelp.shoes;

output;

run;



Answer : B

In SAS, the code you provided involves creating two datasets, table1 and table2, from the dataset sashelp.shoes. The key part to understand here is how the DATA statement and OUTPUT statement interact with the specified datasets.

DATA Statement: The statement data table1 table2; initiates the creation of two new datasets named table1 and table2.

SET Statement: The set sashelp.shoes; statement is used to read data from the sashelp.shoes dataset. This dataset includes data on shoe sales from SASHELP library, which is commonly used for demonstration purposes in SAS.

OUTPUT Statement: In the context of the DATA step where multiple datasets are specified in the DATA statement (as in table1 table2), the OUTPUT statement without a dataset name specified outputs the current observation to all datasets listed in the DATA statement. This is a critical point because it determines where the data goes after processing in the DATA step.

Execution: When the run; statement is executed, it processes each observation from sashelp.shoes. For each observation, because there is no condition or additional OUTPUT statements specifying dataset names, each observation is output to both table1 and table2.

Therefore, the correct behavior as described is that each observation in sashelp.shoes is written to both table1 and table2. This effectively duplicates each row from the source into both target datasets.


SAS 9.4 Language Reference: Concepts, 'DATA Step Processing' and 'OUTPUT Statement' sections provide detailed explanations on how DATA steps process and how OUTPUT statement works in different contexts.

Practical examples and explanations from SAS programming courses and official SAS documentation, which discuss DATA and SET statements, and their interaction with OUTPUT in data duplication scenarios.

Question 3

Given the STUDENTS data set below:

What will be the values for First. State and Last. State for Ellen's observation?



Answer : D

When using a BY statement in a DATA step, SAS creates two temporary variables for each BY variable: FIRST.variable and LAST.variable. These are used to indicate the beginning and end of each BY group.

For Ellen's observation:

First.State=1 because this is the first occurrence of the state 'OH' in the dataset when sorted by the state variable, which makes it the beginning of a new group for 'OH'.

Last.State=0 because Ellen is not the last observation

for the state 'OH' group. In the given dataset snippet, there appears to be only one observation for the state 'OH', but since the data is sorted by state, and we don't see another 'OH' below Ellen, we can deduce that Ellen's observation is not the last 'OH' observation in the entire dataset. If there were no more 'OH' observations following Ellen's, then Last.State would be 1.

The FIRST.variable is set to 1 for the first observation in each BY group and 0 for all other observations in the group. Conversely, LAST.variable is set to 1 for the last observation in each BY group and 0 otherwise. Since we're assuming that the dataset is larger than the snippet shown, and the data continues beyond what is visible, we must assume there are more observations for 'OH' unless indicated otherwise.

Reference

'SAS 9.4 Language Reference: Concepts.' SAS Institute Inc.

'BY-Group Processing' in 'SAS Programming 1: Essentials' course material, SAS Institute.


Question 4

Which sentence is true regarding the VALUE statement in the FORMAT procedure?



Answer : C

In SAS, the FORMAT procedure (PROC FORMAT) allows users to create custom formats that can be used to change the way data is displayed without altering the data itself. The VALUE statement within PROC FORMAT is a key component of this procedure.

The VALUE statement can indeed create both numeric and character formats, which is why option C is correct. Numeric format names typically do not start with a $ sign (this is reserved for character format names), and the keyword UNKNOWN is not a part of the VALUE statement syntax; it is used in a different context within PROC FORMAT, specifically for handling undefined data values when using custom formats.

Moreover, the LIB= option is not used within the VALUE statement. The LIB= option is used at the PROC FORMAT level to specify the library where the formats should be stored or from which they should be read.

Reference

SAS 9.4 documentation for the PROC FORMAT and VALUE statement.

'SAS Formats and Informats.' in 'Step-by-Step Programming with Base SAS 9.4' from the SAS Institute.


Question 5

Which PROC SORT statement specifies the sort variable?



Answer : B

The PROC SORT statement that specifies the sort variable is: BY

The BY statement in PROC SORT is used to specify the variable(s) by which the data should be sorted.


Question 6

Which step reads the SASHELP. BASEBALL data set and creates the temporary data set CATCHERS?



Answer : D

The step that reads the SASHELP.BASEBALL data set and creates the temporary data set CATCHERS is:

data catchers;

set sashelp.baseball;

where position='C';

run;

This DATA step creates a new data set named catchers by reading in data from sashelp.baseball and selecting only those observations where the variable position has the value 'C', which stands for catchers.


Question 7

The data set SASHELP. CARS contains information on different vehicles. How do you correctly write the observations with Type of 'SUV' to the suv data set and Type

of 'Sedan' to the sedans data set?



Answer : B

The correct syntax for creating two separate data sets based on a condition in SAS involves using a single DATA step with multiple data set names followed by a SET statement and conditional OUTPUT statements. Here's a breakdown of why option B is the correct answer:

data SUV Sedans;

set sashelp.cars;

if Type = 'SUV' then output SUV;

else if Type = 'Sedan' then output Sedans;

run;

This option correctly uses a single DATA step to declare two data sets (SUV and Sedans). It reads from the sashelp.cars data set and uses conditional statements to output observations to the respective data sets based on the value of the Type variable. The output statement is used to explicitly direct observations to the specified data set.

Option A: The syntax data=SUV data=Sedans; is incorrect. The correct syntax to create multiple data sets in a DATA step does not include equal signs (=).

Option C: The syntax within the conditional statements is incorrect (if Type = SUV and if Type = Sedan). The values for Type should be enclosed in quotes to specify that they are strings.

Option D: The syntax data= (SUV Sedans) ; is incorrect. The correct method to declare multiple data sets in a DATA step does not use parentheses or an equal sign.

Reference: The correctness of option B is based on standard SAS programming practices for conditional data manipulation within a DATA step. This approach is commonly documented in SAS programming resources such as the SAS 9.4 documentation and various SAS programming guides. The use of the output statement for directing data to specific datasets based on conditions is a fundamental technique in efficient data handling in SAS.


Page:    1 / 14   
Total 78 questions