SAS Chapter 11 Creating And Managing Variables

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Moxleyv
M
Moxleyv
Community Contributor
Quizzes Created: 38 | Total Attempts: 21,992
| Attempts: 423 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. Which of the following can determine the length of a new variable?

Explanation

The length of a variable is determined by its first reference in the DATA step. When creating a new character variable, SAS allocates as many bytes of storage space as there are characters in the first value that it encounters for that variable. The first reference to a new variable can also be made with a LENGTH statement or an assignment statement. The length of the variable's first value does not matter once the variable has been referenced in your program.

Submit
Please wait...
About This Quiz
SAS Chapter 11 Creating And Managing Variables - Quiz

This quiz assesses skills in managing and creating variables in SAS, focusing on data handling, conditional statements, and output customization. It is designed for learners aiming to enhance their proficiency in SAS data management practices.

Personalize your quiz and earn a certificate with your name on it!
2. Which set of statements is equivalent to the code shown below? if code='1' then Type='Fixed'; if code='2' then Type='Variable'; if code^='1' and code^='2' then Type='Unknown';

Explanation

You can write multiple ELSE statements to specify a series of mutually exclusive conditions. The ELSE statement must follow the IF-THEN statement in your program. An ELSE statement executes only if the previous IF-THEN/ELSE statement is false.

Submit
3. Now consider the revised program below.  What is the value of Count after the third observation is read?

Explanation

The RETAIN statement assigns an initial value of 100 to the variable Count, so the value of Count in the third observation would be 100+10+20+0, or 130.

Submit
4. How is the variable Amount labeled and formatted in the PROC PRINT output? data credit;
   infile creddata;
   input Account $ 1-5 Name $ 7-25 Type $27
             Transact $ 29-35 Amount 37-50;
   label amount='Amount of Loan';
   format amount dollar 12.2;
run;
proc print data=credit label;
   label amount='Total Amount Loaned';
   format amount comma10.;
run;

Explanation

The variable Amount is labeled as "Total Amount Loaned" and formatted as "COMMA10." in the PROC PRINT output.

Submit
5. What is the length of the variable Type, as created in the DATA step below? data finance.records;    set finance.records;    TotLoan+payment;    if code='1' then Type='Fixed';    else Type='Variable';    length type $ 10; run;

Explanation

The length of a new variable is determined by the first reference in the DATA step, not by data values. In this case, the length of Type is determined by the value Fixed. The LENGTH statement is in the wrong place; it must be read before any other reference to the variable in the DATA step. The LENGTH statement cannot change the length of an existing variable.

Submit
6. Consider the small raw data file and program shown below.  What is the value of Count after the fourth record is read?

Explanation

The sum statement adds the result of the expression that is on the right side of the plus sign to the numeric variable that is on the left side. The new value is then retained for subsequent observations. The sum statement treats the missing value as a 0, so the value of Count in the fourth observation would be 10+20+0+40, or 70.

Submit
7. Consider the IF-THEN statement shown below.  When the statement is executed, which expression is evaluated first? if finlexam>=95    and (research='A' or        (project='A' and present='A'))    then Grade='A+';

Explanation

Logical comparisons that are enclosed in parenthesis are evaluated as true or false before they are compared to other expressions. In the example above, the AND comparison within the nested parenthesis is evaluated before being compared to the OR comparison.

Submit
8. Which program creates the output shown below?

Explanation

Program c correctly deletes the observation in which the value of Finish is oak and the value of Price is less than 200. It also creates TotalPrice by summing the variable Price down observations, then drops Price by using the DROP= data set option in the DATA statement.

Submit
9. For the observation show below, what is the result of the IF-THEN statements? if status='OK' and type=3    then Count+1; if status='S' or action='E'    then Control='Stop';

Explanation

You must enclose character values in quotation marks, and you must specify them in the same case in which they appear in the data set. The value ok is not identical to OK, so the value of Count i snot changed by the IF-THEN statement.

Submit
10. Which program contains an error?

Explanation

To select variables, you can use a DROP or KEEP statement in any DATA step. You can also use the DROP= or KEEP= data set options following a data set name in any DATA or PROC step. However, you cannot use DROP or KEEP statements in PROC steps.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jan 30, 2013
    Quiz Created by
    Moxleyv
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which of the following can determine the length of a new variable?
Which set of statements is equivalent to the code shown below?...
Now consider the revised program below.  What is the value of...
How is the variable Amount labeled and formatted in the PROC PRINT...
What is the length of the variable Type, as created in the DATA step...
Consider the small raw data file and program shown below.  What...
Consider the IF-THEN statement shown below.  When the statement...
Which program creates the output shown below?
For the observation show below, what is the result of the IF-THEN...
Which program contains an error?
Alert!

Advertisement