Essays
Topics
Writing Tool
Machine Learning AI
ChatGPT
US History
Presidents of the United States
Joseph Robinette Biden
Donald Trump
Barack Obama
US States
States Ranked by Size & Population
States Ranked by Date
IPL
>
Statistics
>
Lesson Quizzes - SAS Programming 2, Data Manipulation Techniques.pdf
Lesson Quizzes - SAS Programming 2, Data Manipulation Techniques
.pdf
School
Hope College
*
*We aren't endorsed by this school
Course
STATISTICS 125
Subject
Statistics
Date
Dec 20, 2024
Pages
90
Uploaded by ProfFerret4819
SAS
®
Programming 2: Data
Manipulation Techniques
Lesson Quizzes
SAS and all other SAS Institute Inc. product or service names are registered trademarks or
trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.
Other brand and product names are trademarks of their respective companies.
SAS
®
Programming 2: Data Manipulation Techniques – Lesson Quizzes
Copyright © 2022 SAS Institute Inc. Cary, NC, USA. All rights reserved. Printed in the United
States of America. No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise,
without the prior written permission of the publisher, SAS Institute Inc.
C
ourse code PG294LQ, prepared date 03Nov2022.
PG294LQ_001
Lesson 1
Lesson Quizzes
1.1
Quizzes
.....................................................................................................................................
1-3
Lesson 1 – Controlling DATA Step Processing
......................................................................
1-3
Lesson 2 – Summarizing Data
...............................................................................................
1-8
Lesson 3 – Manipulating Data with Functions
......................................................................
1-13
Lesson 4 – Creating Custom Formats
..................................................................................
1-18
Lesson 5 – Combining Tables
..............................................................................................
1-23
Lesson 6 – Processing Repetitive Code
..............................................................................
1-28
Lesson 7 – Restructuring Tables
..........................................................................................
1-33
1.2
Solutions
................................................................................................................................
1-38
Lesson 1
...............................................................................................................................
1-38
Lesson 2
...............................................................................................................................
1-46
Lesson 3
...............................................................................................................................
1-53
Lesson 4
...............................................................................................................................
1-59
Lesson 5
...............................................................................................................................
1-65
Lesson 6
...............................................................................................................................
1-74
Lesson 7
...............................................................................................................................
1-79
1-2
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.1
Quizzes
1-3
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.1
Quizzes
Lesson 1 – Controlling DATA Step Processing
Copyright © SAS Institute Inc. All rights reserved.
3
1.
Which statement is false concerning the compilation phase of the DATA
step?
a.
Initial values are assigned to the columns.
b.
The program data vector (PDV) is created.
c.
The DATA step is checked for syntax errors.
d.
The descriptor portion of the output table is created.
Copyright © SAS Institute Inc. All rights reserved.
5
2.
Which statement is not a compile-time-only statement?
a.
KEEP
b.
LENGTH
c.
SET
d.
WHERE
1-4
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
7
3.
Which statement is true concerning the execution phase of the DATA
step?
a.
Data is processed in the program data vector (PDV).
b.
An implied OUTPUT occurs at the top of the DATA step.
c.
An implied REINITIALIZE occurs at the bottom of the DATA step.
d.
Columns read from the input table are set to missing when SAS returns
to the top of the DATA step.
Copyright © SAS Institute Inc. All rights reserved.
9
4.
The DATA step debugger in SAS Enterprise Guide can be used with DATA
and PROC steps.
a.
True
b.
False
1.1
Quizzes
1-5
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
11
5.
Which PUTLOG statements create the following results in the SAS log?
a.
putlog all; putlog Ratio;
b.
putlog all; putlog Ratio=;
c.
putlog _all_; putlog Ratio;
d.
putlog _all_; putlog Ratio=;
Name=Alfred Height=69 Weight=112.5 Ratio=0.61 _ERROR_=0 _N_=1
Ratio=0.61
Copyright © SAS Institute Inc. All rights reserved.
13
6.
How many rows and columns are in the output table ShippingZones
given the following information?
a.
5 rows and 3 columns
b.
5 rows and 4 columns
c.
10 rows and 3 columns
d.
10 rows and 4 columns
data ShippingZones;
set Shipping;
Zone=1;
output;
Zone=2;
Rate=(Rate*1.5);
run;
The input table Shipping
contains 5 rows and 3 columns
(Product, BoxSize, and Rate).
1-6
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
15
7.
Which statement is true given the following information?
a.
The Other table contains 10 rows.
b.
The Other table contains 19 rows.
c.
The Females table contains 10 rows.
d.
The Females table contains 19 rows.
data Females Other;
set sashelp.class;
if sex='F' then
output Females;
output Other;
run;
sashelp.class contains 19 rows:
9 rows with a sex value of
F
and
10 rows with a sex value of
M
.
Copyright © SAS Institute Inc. All rights reserved.
17
8.
Which statement is false?
a.
The KEEP statement names the columns to include from the input table.
b.
The DROP statement names the columns to exclude from the output
table.
c.
The KEEP= option in the DATA statement names the columns to include
in the output table.
d.
The DROP= option in the SET statement names the columns to exclude
from being read into the PDV.
1.1
Quizzes
1-7
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
19
9.
Which columns are in the final table work.boots?
a.
Subsidiary
b.
Subsidiary and Total
c.
Product and Subsidiary
d.
Product, Subsidiary, Sales, and Inventory
data work.boots(drop=Product);
set sashelp.shoes(keep=Product Subsidiary Sales Inventory);
where Product='Boot';
drop Sales Inventory;
Total=sum(Sales,Inventory);
run;
Copyright © SAS Institute Inc. All rights reserved.
21
10.
What is the result of running the following DATA step?
a.
The step produces work.boots with three columns.
b.
The step produces work.boots with four columns.
c.
The step produces an error due to invalid syntax for the KEEP= option.
d.
The step produces an error because the Sales column is not read in from
the sashelp.shoes table.
data work.boots;
set sashelp.shoes(keep=Product Subsidiary);
where Product='Boot';
NewSales=Sales*1.25;
run;
1-8
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 2 – Summarizing Data
Copyright © SAS Institute Inc. All rights reserved.
24
1.
Which statement contains valid syntax for the RETAIN statement?
a.
retain year 2018;
b.
retain year*2018;
c.
retain year=2018;
d.
retain year{2018};
Copyright © SAS Institute Inc. All rights reserved.
26
2.
Which statement is false concerning the sum statement?
a.
The sum statement ignores missing values.
b.
The sum statement initially sets the accumulator column to missing.
c.
The sum statements adds a numeric value to an accumulator column.
d.
The sum statement automatically retains the value of the accumulating
column.
1.1
Quizzes
1-9
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
28
3.
What is the value of Count at the end of the third DATA step iteration?
a.
. (missing)
b.
60
c.
130
d.
160
work.nums
data newnums;
set nums;
retain Count 100;
Count+Tens;
run;
Copyright © SAS Institute Inc. All rights reserved.
30
4.
What is the value of Count at the end of the third DATA step iteration?
a.
. (missing)
b.
20
c.
30
d.
70
work.nums
data newnums;
set nums;
Count+Tens;
run;
1-10
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
32
5.
Which step executes successfully without an error, given the input table
sashelp.class?
a.
b.
c.
d.
data new;
set sashelp.class;
Ratio=Height/Weight;
where Sex='M' & Ratio>0.6;
run;
data new;
set sashelp.class;
where Sex='M’;
Ratio=Height/Weight;
if Ratio>0.6;
run;
data new;
set sashelp.class;
where Sex='M';
Ratio=Height/Weight;
where Ratio>0.6;
run;
data new;
set sashelp.class;
if Sex='M’;
Ratio=Height/Weight;
where Ratio>0.6;
run;
Copyright © SAS Institute Inc. All rights reserved.
34
6.
Which statement is true given the following program?
a.
The PDV contains a temporary variable named First.Name.
b.
The output table work.student contains a column named Last.Name.
c.
The DATA step sorts the input table by the column Name.
d.
An error is produced because the BY statement is not permitted in the
DATA step.
data work.student;
set sashelp.class;
by Name;
run;
1.1
Quizzes
1-11
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
36
7.
What are the correct values for First.Name and Last.Name if the value of
Name appears only once in the input table?
a.
First.Name=0 and Last.Name=0
b.
First.Name=1 and Last.Name=1
c.
First.Name=1 and Last.Name=0
d.
First.Name=0 and Last.Name=1
data work.student;
set sashelp.class;
by Name;
run;
Copyright © SAS Institute Inc. All rights reserved.
38
8.
Which DATA step statement indicates to continue processing the last row
of a BY group?
a.
if First.JobTitle;
b.
if Last.JobTitle;
c.
where First.JobTitle=1;
d.
where Last.JobTitle=1;
1-12
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
40
9.
Which statement needs to be added to the DATA step to reset the value
of TotalWt for each new BY group?
a.
TotalWt=0;
b.
if Last.Gender=0 then TotalWt=0;
c.
if First.Gender=0 then TotalWt=0;
d.
if First.Gender=1 then TotalWt=0;
data GenderWeight;
set Students;
by Gender;
…
add statement here …
TotalWt+Weight;
if Last.Gender=1 then output;
run;
Copyright © SAS Institute Inc. All rights reserved.
42
10.
What are the values for First.City and Last.City for the third row of the
input table given the following information?
a.
First.City=0 and Last.City=0
b.
First.City=1 and Last.City=0
c.
First.City=0 and Last.City=1
d.
First.City=1 and Last.City=1
data StatePopulation;
set Population;
by State City;
run;
1.1
Quizzes
1-13
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 3 – Manipulating Data with Functions
Copyright © SAS Institute Inc. All rights reserved.
45
1.
Functions and CALL routines both return a value that must be used in an
assignment statement or expression.
a.
True
b.
False
Copyright © SAS Institute Inc. All rights reserved.
47
2.
Which function calculates the average of the columns Week1, Week2,
Week3, and Week4?
a.
mean(Week1, Week4)
b. mean(Week1-Week4)
c.
mean(of Week1, Week4)
d.
mean(of Week1-Week4)
1-14
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
49
3.
Which expression rounds each value of Sales to the nearest hundredth
(or two decimal places)?
a.
round(Sales)
b.
round(Sales, 2)
c.
round(Sales, .01)
d.
round(Sales, dollar10.2)
Copyright © SAS Institute Inc. All rights reserved.
51
4.
Which function could be used to remove the non-numeric symbols in
Phone?
a.
COMPRESS
b. COMPBL
c.
SCAN
d. FIND
Phone
202-555-0190
202.555.0110
(202)555-0133
[202]555-0128
1.1
Quizzes
1-15
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
53
5.
Which statement reads CityCountry and correctly assigns a value to
Country?
a.
Country=scan(CityCountry, 2);
b.
Country=scan(CityCountry, -1);
c.
Country=scan(CityCountry, 2, ',');
d.
Country=scan(CityCountry, 2, ',
');
CityCountry
Country
Athens, Greece
Greece
New Delhi, India
India
Auckland,
New Zealand
New Zealand
Copyright © SAS Institute Inc. All rights reserved.
55
6.
Which expression creates CityCountry?
a.
cat(City, ",
", Country)
b.
cats(", ", City, Country)
c.
catx(City, ",
", Country)
d. catx(",
", City, Country)
City
Country
CityCountry
Athens
Greece
Athens, Greece
New Delhi
India
New Delhi, India
Auckland
New Zealand
Auckland,
New Zealand
1-16
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
57
7.
How many rows are written to output based on the following statement?
a.
0
b. 1
c.
3
d. 5
Location
Honolulu, Oahu
Kaanapali, Maui
Hilo, Hawaii
kailua, oahu
LAIE, OAHU
if find(Location, "Oahu", "i") > 0 then output;
Copyright © SAS Institute Inc. All rights reserved.
59
8.
Which of the following functions can convert the values of the numeric
variable Level to character values?
a.
put(Level, 3.)
b.
put(3., Level)
c.
input(3., Level)
d.
input(Level, 3.)
1.1
Quizzes
1-17
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
61
9.
Which of the following functions converts the character values of Base to
numeric values?
a.
put(comma10.2, Base)
b.
put(Base, comma10.2)
c.
input(Base, comma10.2)
d.
input(comma10.2, Base)
Copyright © SAS Institute Inc. All rights reserved.
63
10.
Which step is not required when converting a character column named
Date to a numeric SAS date column with the same name?
a.
Rename the Date column to a new name, such as CharDate.
b.
Use the INPUT function to read the renamed CharDate character
column and create a numeric column named Date.
c.
Specify an appropriate informat in the INPUT function.
d.
Format the new numeric Date column.
1-18
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 4 – Creating Custom Formats
Copyright © SAS Institute Inc. All rights reserved.
66
1.
Which of the following contains valid syntax?
a.
.
b.
.
c.
.
value grades 'A'='Excellent'
'B'='Good';
value qtrfmt 1,2,3='First'
4,5,6='Second';
value $grades. 'A'='Excellent'
'B'='Good';
value qtrfmt '1'-'3'='First'
'4'-'6'='Second';
Copyright © SAS Institute Inc. All rights reserved.
68
2.
What is the formatted value for the value of 100 given the following
step?
a.
low
b.
medium
c.
high
d.
out of range
proc format;
value rates
1-<100='low'
100<-<200='medium'
200-300 ='high'
other ='out of range';
run;
1.1
Quizzes
1-19
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
70
3.
In the FORMAT procedure, you specify the name of the format and the
name of the column that will use the custom format.
a.
True
b.
False
Copyright © SAS Institute Inc. All rights reserved.
72
4.
What is the correct formatted output given the following PROC FORMAT
step and the input table?
a.
b.
c.
d.
proc format;
value $answer '1'='Yes'
'2'='No'
'other'='Not Answered';
run;
1-20
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
74
5.
Which one of the following does not have proper syntax for specifying a
range in the VALUE statement?
a.
500>-700
b.
500-<700
c.
'A'-'C'
d.
'Horse'-'Mouse'
Copyright © SAS Institute Inc. All rights reserved.
76
6.
Which statement is true concerning options for the FORMAT procedure?
a.
The FMTLIB option goes in the SELECT statement.
b.
The CNTLIN= option goes in the VALUE statement.
c.
The FMTLIB option specifies the library to store the format.
d.
The CNTLIN= option specifies a table from which formats are built.
1.1
Quizzes
1-21
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
78
7.
Which columns are required in an input table to create a format based
on numeric ranges?
a.
FMTNAME, START, and LABEL
b.
FORMAT, START, END, and NAME
c.
FMTNAME, START, END, and LABEL
d.
FORMAT, START, LAST, NAME, and TYPE
Copyright © SAS Institute Inc. All rights reserved.
80
8.
Which option in the PROC FORMAT statement specifies a library to store
a custom format?
a.
CATALOG=
b.
FMTLIB=
c.
LIBRARY=
d.
STORE=
1-22
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
82
9.
What is the default search order that is used to locate formats?
a.
LIBRARY.FORMATS
WORK.FORMATS
b.
SASHELP.FORMATS
LIBRARY.FORMATS
c.
SASHELP.FORMATS
WORK.FORMATS
d.
WORK.FORMATS
LIBRARY.FORMATS
Copyright © SAS Institute Inc. All rights reserved.
84
10.
Which of the following contains valid syntax for the FMTSEARCH=
option?
a.
options fmtsearch=sashelp;
b.
options fmtsearch=sashelp.formats;
c.
options fmtsearch=(sashelp sashelp.fmts);
d.
options fmtsearch=[sashelp.fmts sashelp];
1.1
Quizzes
1-23
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 5 – Combining Tables
Copyright © SAS Institute Inc. All rights reserved.
87
1.
Which statement is true concerning concatenating tables?
a.
All tables must have the same number of columns.
b.
Columns in all tables must have matching names and lengths.
c.
Tables must be in the same library.
d.
Missing values are generated for columns that exist in one input table and
not in another.
Copyright © SAS Institute Inc. All rights reserved.
89
2.
Which statement renames the existing column Location in work.travel
as Destination?
a.
b.
c.
d.
A
set vacations travel(rename=(Location=Destination));
set vacations(rename=(Location=Destination)) travel;
set vacations travel(rename=(Destination=Location));
set vacations travel(rename(Destination=Location));
1-24
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
91
3.
Which statement is true concerning merging with matching rows?
a.
The MERGE statement must refer to temporary input tables.
b.
The columns in the BY statement can be in only one of the tables.
c.
Only two input tables can be specified in the MERGE statement.
d.
The input tables must be sorted by the columns in the BY statement.
Copyright © SAS Institute Inc. All rights reserved.
93
4.
How many rows are in the output table given the following?
a.
two
b.
three
c.
four
d.
five
data both;
merge agetable
foodtable;
by Name;
run;
work.agetable
work.foodtable
1.1
Quizzes
1-25
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
95
5.
How many rows are in the output table given the following?
a.
two
b.
three
c.
four
d.
five
data empsauc;
merge empsau phonec;
by EmpID;
run;
work.empsau
work.phonec
Copyright © SAS Institute Inc. All rights reserved.
97
6.
What is the result of the following step?
a.
The table combine is created with four columns and five rows.
b.
The step fails because the BY column ID is not properly sorted.
c.
The step fails because Units is in both tables and not the BY column.
d.
The step fails because of duplicate ID values within the donors1 table.
data combine;
merge donors1 donors2;
by ID;
run;
work.donors1
work.donors2
1-26
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
99
7.
Which statement best describes the rows in the output table?
a.
all the matching rows from both managers and staff
b.
only the rows from managers that have no match in staff
c.
only the rows from staff that have no match in managers
d.
all the matching and nonmatching rows from both managers and staff
data bonuses;
merge managers(in=M)
staff(in=S);
by EmpID;
if M=0 and S=1;
run;
Copyright © SAS Institute Inc. All rights reserved.
101
8.
What are the values of C and A during the third iteration of the DATA
step?
a.
C=0 and A=0
b.
C=1 and A=0
c.
C=0 and A=1
d.
C=1 and A=1
data client_amount;
merge clients(in=C)
amounts(in=A);
by Name;
run;
work.clients
work.amounts
1.1
Quizzes
1-27
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
103
9.
What is the value of Location in the output table?
a.
Italy
b.
France
c.
Belgium
d.
France Belgium Italy
data locALL;
merge loc1 loc2 loc3;
by Code;
run;
loc1
Code
Location
A
France
loc2
Code
Location
A
Belgium
loc3
Code
Location
A
Italy
Copyright © SAS Institute Inc. All rights reserved.
105
10.
A single DATA step can be used to merge the following three tables:
a.
True
b.
False
dataset1
Student
Test
Score
dataset2
Subject
Test
dataset3
Subject
AvgScore
1-28
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 6 – Processing Repetitive Code
Copyright © SAS Institute Inc. All rights reserved.
108
1.
Which output table is produced from the following step?
a.
b.
c.
d.
data Earnings(keep=Qtr Earned);
Amount=1000; Rate=.075/4;
do Qtr=1 to 4;
Earned+(Amount+Earned)*Rate;
end;
run;
Copyright © SAS Institute Inc. All rights reserved.
110
2.
Which statement is true regarding the iterative DO loop?
a.
The start and stop values can be character or numeric values.
b.
If an increment value is not specified, the default increment is 0.
c.
The index column is incremented at the bottom of each DO loop.
d.
The index column is not in the final table unless specifically kept.
DO
index-column
=
start
TO
stop
<BY
increment
> ;
1.1
Quizzes
1-29
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
112
3.
How many rows are in the output table given the following?
a.
1
b.
4
c.
5
d.
20
data work.savings;
set pg2.savings;
Savings=0;
do Year=1 to 5;
do qtr=1 to 4;
Savings+Amount;
Savings+(Savings*0.02/12);
end;
end;
run;
pg2.savings
Copyright © SAS Institute Inc. All rights reserved.
114
4.
What is the final value of Year given the following step?
a.
. (missing)
b.
2010
c.
2019
d.
2020
data invest;
do Year=2010 to 2019;
Capital+5000;
Capital+(Capital*.03);
end;
run;
1-30
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
116
5.
Which of the following statements contains valid syntax?
a.
do 1 to 10 by 2;
b.
do while (Year>2025);
c.
do until Earnings<=100000;
d.
do date='01JAN2019' to '31JAN2019';
Copyright © SAS Institute Inc. All rights reserved.
118
6.
How many rows are in the output table given the following?
a.
2
b.
3
c.
6
d.
12
e.
24
data bikeinfo2;
set bikeinfo;
do month=1 to 3;
do week=1 to 4;
bike=bike+2;
end;
output;
end;
run;
work.bikeinfo
1.1
Quizzes
1-31
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
120
7.
What is the value of x at the completion of the DATA step?
a.
. (missing)
b.
13
c.
15
d.
16
data test;
x=15;
do until(x>12);
x+1;
end;
run;
Copyright © SAS Institute Inc. All rights reserved.
122
8.
Which statement is false?
a.
The DO UNTIL loop executes until a condition is true.
b.
The DO WHILE loop always executes at least one time.
c.
The DO WHILE loop checks the condition at the top of the loop.
d.
The DO UNTIL loop checks the condition at the bottom of the loop.
1-32
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
124
9.
Which of the following statements contains valid syntax?
a.
do Age=10 to 14 and while (Weight<150);
b.
do week=1 to 52 do until (Mileage ge 2750);
c.
do Increase=5 to 10 while (temperature lt 102);
d.
do Year=2018 to 2028 or until (Earnings<=100000);
Copyright © SAS Institute Inc. All rights reserved.
126
10.
Which output table is produced from the following step?
a.
b.
c.
d.
data test;
bike=10;
do day=1 to 7 while (bike lt 13);
bike=bike+2;
end;
run;
1.1
Quizzes
1-33
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 7 – Restructuring Tables
Copyright © SAS Institute Inc. All rights reserved.
129
1.
Which is the better description for the following table?
a.
wide table
b.
narrow table
Copyright © SAS Institute Inc. All rights reserved.
131
2.
Which statement is needed for creating multiple rows from a single row
when using the DATA step to go from a wide to a narrow table?
a.
WIDE
b.
NARROW
c.
RETAIN
d.
OUTPUT
1-34
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
133
3.
How many rows will be in the final table if work.airwide contains three
rows?
a.
3
b.
6
c.
9
d.
12
data work.airnarrow;
set work.airwide;
Month='Jan';
Air=Jan;
output;
Month='Feb';
Air=Feb;
output;
Month='Mar';
Air=Mar;
output;
keep Year Month Air;
run;
Copyright © SAS Institute Inc. All rights reserved.
135
4.
When using the DATA step to go from a narrow table to a wide table, the
KEEP statement is needed to hold values in the PDV across multiple
iterations of the DATA step.
a.
True
b.
False
1.1
Quizzes
1-35
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
137
5.
Which statement needs to be added to the DATA step to include only the
last row per Year in the output table?
a.
output;
b.
if Last then output;
c.
if Last.Year=1 then output;
d.
if Last.Year=0 then output;
data work.airwide2(keep=Year Jan Feb Mar);
set work.airnarrow;
by Year;
retain Jan Feb Mar;
if Month='Jan' then Jan=Air;
else if Month='Feb' then Feb=Air;
else if Month='Mar' then Mar=Air;
...
insert statement here
...
run;
Copyright © SAS Institute Inc. All rights reserved.
139
6.
Which statement is false concerning the TRANSPOSE procedure?
a.
Columns are transposed into rows.
b.
By default, numeric columns are transposed.
c.
Use a BY statement to sort the data while transposing.
d.
Use a VAR statement to specifically specify the character and numeric
columns to transpose.
1-36
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
141
7.
Which statements are needed in a PROC TRANSPOSE step for the
following example (narrow
wide)?
a.
b.
c.
d.
by Day;
id Food;
var Meal;
by Day;
var Meal Food;
id Day;
var Food Meal;
by Day;
id Meal;
var Food;
Copyright © SAS Institute Inc. All rights reserved.
143
8.
Which statement or statements are needed in a PROC TRANSPOSE step
for the following example (wide
narrow)?
a.
b.
c.
d.
id Day;
by Day;
var Breakfast Lunch Dinner;
id Day;
var Breakfast Lunch Dinner;
1.1
Quizzes
1-37
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Copyright © SAS Institute Inc. All rights reserved.
145
9.
Which option is needed in the PROC TRANSPOSE statement to rename
the _NAME_ column?
a.
_name_=Meal
b.
name=Meal
c.
prefix=Meal
d.
rename=Meal
Copyright © SAS Institute Inc. All rights reserved.
147
10.
Which option is needed in the PROC TRANSPOSE statement to rename
the COL columns?
a.
out=meals2(COL1=Day_7 COL2=Day_1)
b.
out=meals2(name=(COL1=Day_7 COL2=Day_1))
c.
out=meals2(rename=(COL1=Day_7 COL2=Day_1))
d.
out=meals2(prefix=(COL1=Day_7 COL2=Day_1))
1-38
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
1.2
Solutions
Lesson 1
Initial values are assigned to columns at the beginning of the execution phase.
Copyright © SAS Institute Inc. All rights reserved.
4
1.
Which statement is false concerning the compilation phase of the DATA
step?
a.
Initial values are assigned to the columns.
b.
The program data vector (PDV) is created.
c.
The DATA step is checked for syntax errors.
d.
The descriptor portion of the output table is created.
1.2
Solutions
1-39
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
At execution time, the SET statement is processed to read data into the PDV. The compile-time
statements of KEEP, LENGTH, and WHERE are not processed at execution time. The rules of these
statements are processed in the compilation phase so that their impact will be observed in the output
table.
During execution, data manipulation occurs in the PDV. An implied OUTPUT and RETURN (not
REINITIALIZE) occurs at the bottom of the DATA step. When SAS returns to the top of the DATA
step, columns read from the input table are retained and computed columns are set to missing.
Copyright © SAS Institute Inc. All rights reserved.
6
2.
Which statement is not a compile-time-only statement?
a.
KEEP
b.
LENGTH
c.
SET
d.
WHERE
Copyright © SAS Institute Inc. All rights reserved.
8
3.
Which statement is true concerning the execution phase of the DATA
step?
a.
Data is processed in the program data vector (PDV).
b.
An implied OUTPUT occurs at the top of the DATA step.
c.
An implied REINITIALIZE occurs at the bottom of the DATA step.
d.
Columns read from the input table are set to missing when SAS returns
to the top of the DATA step.
1-40
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The Data step debugger in SAS Enterprise Guide works only with DATA steps.
Copyright © SAS Institute Inc. All rights reserved.
10
4.
The DATA step debugger in SAS Enterprise Guide can be used with DATA
and PROC steps.
a.
True
b.
False
1.2
Solutions
1-41
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
_ALL_ is a keyword to show all of the contents of the PDV. Ratio= writes out the column name, an
equal sign, and the value of Ratio. Ratio writes out only the value.
data new;
set sashelp.class(keep=Name Height Weight);
Ratio=round(Height/Weight,.01);
putlog all; putlog Ratio=;
run;
Copyright © SAS Institute Inc. All rights reserved.
12
5.
Which PUTLOG statements create the following results in the SAS log?
a.
putlog all; putlog Ratio;
b.
putlog all; putlog Ratio=;
c.
putlog _all_; putlog Ratio;
d.
putlog _all_; putlog Ratio=;
Name=Alfred Height=69 Weight=112.5 Ratio=0.61 _ERROR_=0 _N_=1
Ratio=0.61
1-42
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The explicit OUTPUT statement is sending the ZONE=1 rows to the output table. There is no explicit
OUTPUT statement after ZONE=2, so those rows are not making it to the output table. An implicit
OUTPUT is not at the bottom of the DATA step due to the explicit OUTPUT. The four columns are
Product, BoxSize, Rate, and Zone.
Note:
There were 5 observations read from the data set WORK.SHIPPING.
Note:
The data set WORK.SHIPPINGZONES has 5 observations and 4 variables.
data Shipping;
input Product $ BoxSize Rate;
datalines;
A 5 10
B 6 11
C 7 12
D 8 13
E 9 13
;
data ShippingZones;
set Shipping;
Zone=1;
output;
Zone=2;
Rate=(Rate*1.5);
run;
Copyright © SAS Institute Inc. All rights reserved.
14
6.
How many rows and columns are in the output table ShippingZones
given the following information?
a.
5 rows and 3 columns
b.
5 rows and 4 columns
c.
10 rows and 3 columns
d.
10 rows and 4 columns
data ShippingZones;
set Shipping;
Zone=1;
output;
Zone=2;
Rate=(Rate*1.5);
run;
The input table Shipping
contains 5 rows and 3 columns
(Product, BoxSize, and Rate).
1.2
Solutions
1-43
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The Females table will contain 9 rows and the Other table will contain 19 rows.
The KEEP statement controls which columns are in the output table.
Copyright © SAS Institute Inc. All rights reserved.
16
7.
Which statement is true given the following information?
a.
The Other table contains 10 rows.
b.
The Other table contains 19 rows.
c.
The Females table contains 10 rows.
d.
The Females table contains 19 rows.
data Females Other;
set sashelp.class;
if sex='F' then
output Females;
output Other;
run;
sashelp.class contains 19 rows:
9 rows with a sex value of
F
and
10 rows with a sex value of
M
.
Copyright © SAS Institute Inc. All rights reserved.
18
8.
Which statement is false?
a.
The KEEP statement names the columns to include from the input table.
b.
The DROP statement names the columns to exclude from the output
table.
c.
The KEEP= option in the DATA statement names the columns to include
in the output table.
d.
The DROP= option in the SET statement names the columns to exclude
from being read into the PDV.
1-44
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The column Subsidiary from the input table and the calculated column Total are in the final table.
Product, Sales, and Inventory are dropped.
Note:
The data set WORK.BOOTS has 52 observations and 2 variables.
Copyright © SAS Institute Inc. All rights reserved.
20
9.
Which columns are in the final table work.boots?
a.
Subsidiary
b.
Subsidiary and Total
c.
Product and Subsidiary
d.
Product, Subsidiary, Sales, and Inventory
data work.boots(drop=Product);
set sashelp.shoes(keep=Product Subsidiary Sales Inventory);
where Product='Boot';
drop Sales Inventory;
Total=sum(Sales,Inventory);
run;
1.2
Solutions
1-45
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
work.boots is created with the columns of Product, Subsidiary, NewSales, and Sales. The values of
NewSales and Sales are missing. Sales is uninitialized because the value was not read in from the
input table.
Note:
Variable Sales is uninitialized.
Note:
Missing values were generated as a result of performing an operation on missing values.
Note:
There were 52 observations read from the data set SASHELP.SHOES.
WHERE Product='Boot';
Note:
The data set WORK.BOOTS has 52 observations and 4 variables.
Copyright © SAS Institute Inc. All rights reserved.
22
10.
What is the result of running the following DATA step?
a.
The step produces work.boots with three columns.
b.
The step produces work.boots with four columns.
c.
The step produces an error due to invalid syntax for the KEEP= option.
d.
The step produces an error because the Sales column is not read in from
the sashelp.shoes table.
data work.boots;
set sashelp.shoes(keep=Product Subsidiary);
where Product='Boot';
NewSales=Sales*1.25;
run;
1-46
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 2
Year
is the column to retain with an initial value of
2018
. A space goes between the retain column
and the initial value.
The sum statement ignores missing values, initially sets the accumulator column to 0, adds a
numeric value to an accumulator column, and automatically retains the value of the accumulator
column.
Copyright © SAS Institute Inc. All rights reserved.
25
1.
Which statement contains valid syntax for the RETAIN statement?
a.
retain year 2018;
b.
retain year*2018;
c.
retain year=2018;
d.
retain year{2018};
Copyright © SAS Institute Inc. All rights reserved.
27
2.
Which statement is false concerning the sum statement?
a.
The sum statement ignores missing values.
b.
The sum statement initially sets the accumulator column to missing.
c.
The sum statements adds a numeric value to an accumulator column.
d.
The sum statement automatically retains the value of the accumulating
column.
1.2
Solutions
1-47
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The initial value of
Count
is 100. The end of the first iteration is 100+10=110. The end of the second
iteration is 110+20=130. The end of the third iteration is 130+30=160.
data nums;
input Tens;
datalines;
10
20
30
40
;
run;
data newnums;
set nums;
retain Count 100;
Count+Tens;
run;
Copyright © SAS Institute Inc. All rights reserved.
29
3.
What is the value of Count at the end of the third DATA step iteration?
a.
. (missing)
b.
60
c.
130
d.
160
work.nums
data newnums;
set nums;
retain Count 100;
Count+Tens;
run;
1-48
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The initial value of
Count
is 0. The end of the first iteration is 0+10=10. The end of the second
iteration is 10+20=30. The end of the third iteration is 30+.=30. The sum statement ignores missing
values.
data nums;
input Tens;
datalines;
10
20
.
40
;
run;
data newnums;
set nums;
retain Count 100;
Count+Tens;
run;
Copyright © SAS Institute Inc. All rights reserved.
31
4.
What is the value of Count at the end of the third DATA step iteration?
a.
. (missing)
b.
20
c.
30
d.
70
work.nums
data newnums;
set nums;
Count+Tens;
run;
1.2
Solutions
1-49
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The WHERE statement subsets data as it is being read into the PDV.
Ratio
is not in the input table,
so
Ratio
cannot be specified in the WHERE statement. To subset
Ratio
, the condition must be
specified in an IF statement.
The BY statement produces the columns
First.Name
and
Last.Name
in the PDV, assuming the
input table is sorted by
Name
. These columns will not be in the output table.
Copyright © SAS Institute Inc. All rights reserved.
33
5.
Which step executes successfully without an error, given the input table
sashelp.class?
a.
b.
c.
d.
data new;
set sashelp.class;
Ratio=Height/Weight;
where Sex='M' & Ratio>0.6;
run;
data new;
set sashelp.class;
where Sex='M’;
Ratio=Height/Weight;
if Ratio>0.6;
run;
data new;
set sashelp.class;
where Sex='M';
Ratio=Height/Weight;
where Ratio>0.6;
run;
data new;
set sashelp.class;
if Sex='M’;
Ratio=Height/Weight;
where Ratio>0.6;
run;
Copyright © SAS Institute Inc. All rights reserved.
35
6.
Which statement is true given the following program?
a.
The PDV contains a temporary variable named First.Name.
b.
The output table work.student contains a column named Last.Name.
c.
The DATA step sorts the input table by the column Name.
d.
An error is produced because the BY statement is not permitted in the
DATA step.
data work.student;
set sashelp.class;
by Name;
run;
1-50
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
If
First.Name
and
Last.Name
are both equal to 1, the
Name
value is unique to that row. It is the first
time and the last time that the
Name
value appears.
This statement is true if
Last.Jobtitle
is equal to a nonzero or nonmissing value. Therefore, this
statement is true when
Last.Jobtitle
is equal to 1.
Copyright © SAS Institute Inc. All rights reserved.
37
7.
What are the correct values for First.Name and Last.Name if the value of
Name appears only once in the input table?
a.
First.Name=0 and Last.Name=0
b.
First.Name=1 and Last.Name=1
c.
First.Name=1 and Last.Name=0
d.
First.Name=0 and Last.Name=1
data work.student;
set sashelp.class;
by Name;
run;
Copyright © SAS Institute Inc. All rights reserved.
39
8.
Which DATA step statement indicates to continue processing the last row
of a BY group?
a.
if First.JobTitle;
b.
if Last.JobTitle;
c.
where First.JobTitle=1;
d.
where Last.JobTitle=1;
1.2
Solutions
1-51
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
First.Gender=1
represents the beginning of each new BY group. When
First.Gender
is equal to 1,
the value of the accumulator column needs to be set to 0.
proc sort data=sashelp.class out=students(rename=(Sex=Gender));
by Sex;
run;
data GenderWeight;
set Students;
by Gender;
if First.Gender=1 then TotalWt=0;
TotalWt+Weight;
if Last.Gender=1 then output;
run;
Copyright © SAS Institute Inc. All rights reserved.
41
9.
Which statement needs to be added to the DATA step to reset the value
of TotalWt for each new BY group?
a.
TotalWt=0;
b.
if Last.Gender=0 then TotalWt=0;
c.
if First.Gender=0 then TotalWt=0;
d.
if First.Gender=1 then TotalWt=0;
data GenderWeight;
set Students;
by Gender;
…
add statement here …
TotalWt+Weight;
if Last.Gender=1 then output;
run;
1-52
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The values of
First.City
and
Last.City
are dependent on the values of
State
. For the third row,
First.City
is equal to 1 because that is the first time that Greenville appears within NC.
Last.City
is
equal to 1 because that is the last time Greenville appears within NC.
State=NC City=Cary Population=162320 FIRST.State=1 LAST.State=0 FIRST.City=1 LAST.City=1
_ERROR_=0 _N_=1
State=NC City=Durham Population=263016 FIRST.State=0 LAST.State=0 FIRST.City=1
LAST.City=1 _ERROR_=0 _N_=2
State=NC City=Greenville Population=91495 FIRST.State=0 LAST.State=1 FIRST.City=1
LAST.City=1 _ERROR_=0 _N_=3
State=SC City=Greenville Population=67453 FIRST.State=1 LAST.State=0 FIRST.City=1
LAST.City=1 _ERROR_=0 _N_=4
State=SC City=Sumter Population=40723 FIRST.State=0 LAST.State=1 FIRST.City=1 LAST.City=1
_ERROR_=0 _N_=5
Copyright © SAS Institute Inc. All rights reserved.
43
10.
What are the values for First.City and Last.City for the third row of the
input table given the following information?
a.
First.City=0 and Last.City=0
b.
First.City=1 and Last.City=0
c.
First.City=0 and Last.City=1
d.
First.City=1 and Last.City=1
data StatePopulation;
set Population;
by State City;
run;
1.2
Solutions
1-53
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
data Population;
input State $ City $11. Population;
datalines;
NC Cary
162320
NC Durham
263016
NC Greenville
91495
SC Greenville
67453
SC Sumter
40723
;
run;
data StatePopulation;
set Population;
by State City;
put _all_;
run;
Lesson 3
A function returns a value that must be used in an assignment statement or expression, but a CALL
routine alters existing column values or performs other system functions.
Copyright © SAS Institute Inc. All rights reserved.
46
1.
Functions and CALL routines both return a value that must be used in an
assignment statement or expression.
a.
True
b.
False
1-54
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Numeric column lists are specified with a hyphen between the first and last columns in the range.
The keyword OF must be used if a column list is used as an argument in a function.
Use the second argument in the ROUND function to specify the rounding unit.
Copyright © SAS Institute Inc. All rights reserved.
48
2.
Which function calculates the average of the columns Week1, Week2,
Week3, and Week4?
a.
mean(Week1, Week4)
b. mean(Week1-Week4)
c.
mean(of Week1, Week4)
d.
mean(of Week1-Week4)
Copyright © SAS Institute Inc. All rights reserved.
50
3.
Which expression rounds each value of Sales to the nearest hundredth
(or two decimal places)?
a.
round(Sales)
b.
round(Sales, 2)
c.
round(Sales, .01)
d.
round(Sales, dollar10.2)
1.2
Solutions
1-55
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The second argument of the COMPRESS function can be used to specify all symbols to remove
from the values of
Phone
. The optional third argument of COMPRESS could further simplify this
code by working with entire character classes instead of having to specify individual characters. For
example, the ‘d’ modifier specifies only digits, and the ‘k’ modifier instructs COMPRESS to keep the
specified items instead of removing them. So specifying ‘kd’ for the third argument causes
COMPRESS to keep only digits.
The SCAN function should return the second word using only the comma as a delimiter.
Copyright © SAS Institute Inc. All rights reserved.
52
4.
Which function could be used to remove the non-numeric symbols in
Phone?
a.
COMPRESS
b. COMPBL
c.
SCAN
d. FIND
or
Phone
202-555-0190
202.555.0110
(202)555-0133
[202]555-0128
Phone=compress(Phone, '-.()[] ');
Phone=compress(Phone,,'kd');
Copyright © SAS Institute Inc. All rights reserved.
54
5.
Which statement reads CityCountry and correctly assigns a value to
Country?
a.
Country=scan(CityCountry, 2);
b.
Country=scan(CityCountry, -1);
c.
Country=scan(CityCountry, 2, ',');
d.
Country=scan(CityCountry, 2, ',
');
CityCountry
Country
Athens, Greece
Greece
New Delhi, India
India
Auckland,
New Zealand
New Zealand
1-56
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The CATX function concatenates strings together, removes leading and training blanks, and inserts
the separator that is defined as the first argument.
The “I” modifier as the third argument in the FIND function makes the search case insensitive.
Copyright © SAS Institute Inc. All rights reserved.
56
6.
Which expression creates CityCountry?
a.
cat(City, ",
", Country)
b.
cats(", ", City, Country)
c.
catx(City, ",
", Country)
d. catx(",
", City, Country)
City
Country
CityCountry
Athens
Greece
Athens, Greece
New Delhi
India
New Delhi, India
Auckland
New Zealand
Auckland,
New Zealand
Copyright © SAS Institute Inc. All rights reserved.
58
7.
How many rows are written to output based on the following statement?
a.
0
b. 1
c.
3
d. 5
Location
Honolulu, Oahu
Kaanapali, Maui
Hilo, Hawaii
kailua, oahu
LAIE, OAHU
if find(Location, "Oahu", "i") > 0 then output;
1.2
Solutions
1-57
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The PUT function explicitly converts numeric values to character values. You specify the keyword
PUT followed by the variable name and then the format. The variable name and format are enclosed
in parentheses and separated by a comma.
The INPUT function explicitly converts character values to numeric values. You specify the keyword
INPUT followed by the variable name and then the informat. The variable name and informat are
enclosed in parentheses and separated by a comma. A numeric informat is needed for character-to-
numeric conversions.
Copyright © SAS Institute Inc. All rights reserved.
60
8.
Which of the following functions can convert the values of the numeric
variable Level to character values?
a.
put(Level, 3.)
b.
put(3., Level)
c.
input(3., Level)
d.
input(Level, 3.)
Copyright © SAS Institute Inc. All rights reserved.
62
9.
Which of the following functions converts the character values of Base to
numeric values?
a.
put(comma10.2, Base)
b.
put(Base, comma10.2)
c.
input(Base, comma10.2)
d.
input(comma10.2, Base)
1-58
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Formatting the new column is not required but is recommended.
Copyright © SAS Institute Inc. All rights reserved.
64
10.
Which step is not required when converting a character column named
Date to a numeric SAS date column with the same name?
a.
Rename the Date column to a new name, such as CharDate.
b.
Use the INPUT function to read the renamed CharDate character
column and create a numeric column named Date.
c.
Specify an appropriate informat in the INPUT function.
d.
Format the new numeric Date column.
1.2
Solutions
1-59
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 4
This VALUE statement is creating a numeric format and numeric values are specified.
a.
This VALUE statement is creating a numeric format but character values are specified.
ERROR: The quoted string 'A' is not acceptable to a numeric format or informat.
c.
This VALUE statement contains a period in the format name.
ERROR 22-322: Syntax error, expecting one of the following: a name, $.
ERROR 200-322: The symbol is not recognized and will be ignored
d.
This VALUE statement is creating a numeric format but character values are specified.
ERROR: The quoted string '1' is not acceptable to a numeric format or informat.
Copyright © SAS Institute Inc. All rights reserved.
67
1.
Which of the following contains valid syntax?
a.
.
b.
.
c.
.
value grades 'A'='Excellent'
'B'='Good';
value qtrfmt 1,2,3='First'
4,5,6='Second';
value $grades. 'A'='Excellent'
'B'='Good';
value qtrfmt '1'-'3'='First'
'4'-'6'='Second';
1-60
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
100 falls into the OTHER category. 1-<100 is less than 100. 100<-<200 is greater than 100.
The format name is specified in the VALUE statement of PROC FORMAT. However, PROC
FORMAT has no reference to the table or column to be formatted. Those items appear in other steps
such as a FORMAT statement within PROC PRINT.
Copyright © SAS Institute Inc. All rights reserved.
69
2.
What is the formatted value for the value of 100 given the following
step?
a.
low
b.
medium
c.
high
d.
out of range
proc format;
value rates
1-<100='low'
100<-<200='medium'
200-300 ='high'
other ='out of range';
run;
Copyright © SAS Institute Inc. All rights reserved.
71
3.
In the FORMAT procedure, you specify the name of the format and the
name of the column that will use the custom format.
a.
True
b.
False
1.2
Solutions
1-61
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The word OTHER is in quotation marks. Therefore, it is not seen as a keyword. A value of 3 is not
referenced by any of the values in the VALUE statement. The value 3 will be displayed as 3.
proc format;
value $answer '1'='Yes'
'2'='No'
'other'='Not Answered';
run;
data new;
input Code $;
datalines;
1
2
3
;
run;
proc print data=new noobs;
format Code $answer.;
run;
Copyright © SAS Institute Inc. All rights reserved.
73
4.
What is the correct formatted output given the following PROC FORMAT
step and the input table?
a.
b.
c.
d.
proc format;
value $answer '1'='Yes'
'2'='No'
'other'='Not Answered';
run;
1-62
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The greater than symbol is not valid for a range. The less than symbol can be used after the starting
value or before the ending value.
CNTLIN= specifies the table to read in order to create a format. This option goes in the PROC
FORMAT statement. The FMTLIB option goes in the PROC FORMAT statement and creates a report
containing information about your custom formats.
Copyright © SAS Institute Inc. All rights reserved.
75
5.
Which one of the following does not have proper syntax for specifying a
range in the VALUE statement?
a.
500>-700
b.
500-<700
c.
'A'-'C'
d.
'Horse'-'Mouse'
Copyright © SAS Institute Inc. All rights reserved.
77
6.
Which statement is true concerning options for the FORMAT procedure?
a.
The FMTLIB option goes in the SELECT statement.
b.
The CNTLIN= option goes in the VALUE statement.
c.
The FMTLIB option specifies the library to store the format.
d.
The CNTLIN= option specifies a table from which formats are built.
1.2
Solutions
1-63
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
At a minimum, FMTNAME, START, and LABEL are required for a CNTLIN= table. END is also
needed for ranges.
The LIBRARY= option specifies the library or catalog (or both) that contains the formats that you are
creating. The FMTLIB= option creates a report containing information about your custom formats.
There is not a CATALOG= or STORE= option in the PROC FORMAT statement.
Copyright © SAS Institute Inc. All rights reserved.
79
7.
Which columns are required in an input table to create a format based
on numeric ranges?
a.
FMTNAME, START, and LABEL
b.
FORMAT, START, END, and NAME
c.
FMTNAME, START, END, and LABEL
d.
FORMAT, START, LAST, NAME, and TYPE
Copyright © SAS Institute Inc. All rights reserved.
81
8.
Which option in the PROC FORMAT statement specifies a library to store
a custom format?
a.
CATALOG=
b.
FMTLIB=
c.
LIBRARY=
d.
STORE=
1-64
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
By default, SAS first looks in WORK.FORMATS. If the format is not in that location, SAS looks in
LIBRARY.FORMATS.
The FMTSEARCH= option must specify search criteria in parentheses. After looking in the default
locations, SAS looks in SASHELP.FORMATS and then SASHELP.FMTS.
Copyright © SAS Institute Inc. All rights reserved.
83
9.
What is the default search order that is used to locate formats?
a.
LIBRARY.FORMATS
WORK.FORMATS
b.
SASHELP.FORMATS
LIBRARY.FORMATS
c.
SASHELP.FORMATS
WORK.FORMATS
d.
WORK.FORMATS
LIBRARY.FORMATS
Copyright © SAS Institute Inc. All rights reserved.
85
10.
Which of the following contains valid syntax for the FMTSEARCH=
option?
a.
options fmtsearch=sashelp;
b.
options fmtsearch=sashelp.formats;
c.
options fmtsearch=(sashelp sashelp.fmts);
d.
options fmtsearch=[sashelp.fmts sashelp];
1.2
Solutions
1-65
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 5
Tables with different columns can be concatenated, but missing values are generated for columns
that exist in one input table and not in another.
Parentheses surround all data set options, and another set of parentheses surrounds the columns
listed for the RENAME= data set option.
Copyright © SAS Institute Inc. All rights reserved.
88
1.
Which statement is true concerning concatenating tables?
a.
All tables must have the same number of columns.
b.
Columns in all tables must have matching names and lengths.
c.
Tables must be in the same library.
d.
Missing values are generated for columns that exist in one input table and
not in another.
Copyright © SAS Institute Inc. All rights reserved.
90
2.
Which statement renames the existing column Location in work.travel
as Destination?
a.
b.
c.
d.
A
set vacations travel(rename=(Location=Destination));
set vacations(rename=(Location=Destination)) travel;
set vacations travel(rename=(Destination=Location));
set vacations travel(rename(Destination=Location));
1-66
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
With match-merging, each input table must first be sorted on the values of the BY columns or have
an appropriate index.
There will be two rows for Bob and three rows for Sue.
Note:
There were 2 observations read from the data set WORK.AGETABLE.
Note:
There were 5 observations read from the data set WORK.FOODTABLE.
Copyright © SAS Institute Inc. All rights reserved.
92
3.
Which statement is true concerning merging with matching rows?
a.
The MERGE statement must refer to temporary input tables.
b.
The columns in the BY statement can be in only one of the tables.
c.
Only two input tables can be specified in the MERGE statement.
d.
The input tables must be sorted by the columns in the BY statement.
Copyright © SAS Institute Inc. All rights reserved.
94
4.
How many rows are in the output table given the following?
a.
two
b.
three
c.
four
d.
five
data both;
merge agetable
foodtable;
by Name;
run;
work.agetable
work.foodtable
1.2
Solutions
1-67
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Note:
The data set WORK.BOTH has 5 observations and 3 variables.
data agetable;
input Name $ Age;
datalines;
Bob 12
Sue 15
;
run;
data foodtable;
input Name $ Food $;
datalines;
Bob Pizza
Bob Cupcakes
Sue Burgers
Sue Grapes
Sue Brownies
;
data both;
merge agetable foodtable;
by Name;
run;
1-68
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
There will be a matching row for 121150, a nonmatching row for 121151, a matching row for 121152,
and a nonmatching row for 121153.
Note:
There were 3 observations read from the data set WORK.EMPSAU.
Note:
There were 3 observations read from the data set WORK.PHONEC.
Note:
The data set WORK.EMPSAUC has 4 observations and 4 variables.
data empsau;
input First $ Gender $ EmpID;
datalines;
Togar
M
121150
Kylie
F
121151
Birin
M
121152
;
data phonec;
input EmpID Phone $15.;
datalines;
121150 +61(2)5555-1795
121152 +61(2)5555-1667
121153 +61(2)5555-1348
;
data empsauc;
merge empsau phonec;
by EmpID;
run;
Copyright © SAS Institute Inc. All rights reserved.
96
5.
How many rows are in the output table given the following?
a.
two
b.
three
c.
four
d.
five
data empsauc;
merge empsau phonec;
by EmpID;
run;
work.empsau
work.phonec
1.2
Solutions
1-69
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The two tables are not sorted by ID, so the step produces an error.
ERROR: BY variables are not properly sorted on data set WORK.DONORS1.
data donors1;
input ID Type $ Units;
datalines;
2304 O 16
1129 A 48
1129 A 50
2486 B 63
;
run;
data donors2;
input ID Code $ Units;
datalines;
1129 63 32
2304 61 45
1387 64 67
;
run;
data combine;
merge donors1 donors2;
by ID;
run;
Copyright © SAS Institute Inc. All rights reserved.
98
6.
What is the result of the following step?
a.
The table combine is created with four columns and five rows.
b.
The step fails because the BY column ID is not properly sorted.
c.
The step fails because Units is in both tables and not the BY column.
d.
The step fails because of duplicate ID values within the donors1 table.
data combine;
merge donors1 donors2;
by ID;
run;
work.donors1
work.donors2
1-70
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
S=1 specifies that the
staff
table must contribute to the row, and M=0 specifies that the
managers
table must not contribute to the row.
Copyright © SAS Institute Inc. All rights reserved.
100
7.
Which statement best describes the rows in the output table?
a.
all the matching rows from both managers and staff
b.
only the rows from managers that have no match in staff
c.
only the rows from staff that have no match in managers
d.
all the matching and nonmatching rows from both managers and staff
data bonuses;
merge managers(in=M)
staff(in=S);
by EmpID;
if M=0 and S=1;
run;
1.2
Solutions
1-71
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The third iteration is for the nonmatch of
Davis
.
Davis
is in the
clients
table (C=1) and not the
amounts
table (A=0).
C=1 A=1 Name=Ankerton ID=11123 Amt=92 FIRST.Name=1 LAST.Name=0 _ERROR_=0 _N_=1
C=1 A=1 Name=Ankerton ID=11123 Amt=43 FIRST.Name=0 LAST.Name=1 _ERROR_=0 _N_=2
C=1 A=0 Name=Davis ID=22298 Amt=. FIRST.Name=1 LAST.Name=1 _ERROR_=0 _N_=3
C=1 A=1 Name=Masters ID=33351 Amt=27 FIRST.Name=1 LAST.Name=1 _ERROR_=0 _N_=4
data clients;
input Name $ ID;
datalines;
Ankerton 11123
Davis 22298
Masters 33351
;
data amounts;
input Name $ Amt;
datalines;
Ankerton 92
Ankerton 43
Masters 27
;
Copyright © SAS Institute Inc. All rights reserved.
102
8.
What are the values of C and A during the third iteration of the DATA
step?
a.
C=0 and A=0
b.
C=1 and A=0
c.
C=0 and A=1
d.
C=1 and A=1
data client_amount;
merge clients(in=C)
amounts(in=A);
by Name;
run;
work.clients
work.amounts
1-72
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
data client_amount;
merge clients(in=C)
amounts(in=A);
by Name;
putlog _all_;
run;
The value of
Location
is based on the last table read. The loc3 table has a value of
Italy
for
Location
.
data loc1;
input Code $ Location $;
datalines;
A France
;
data loc2;
input Code $ Location $;
datalines;
A Belgium
;
data loc3;
input Code $ Location $;
datalines;
A Italy
;
Copyright © SAS Institute Inc. All rights reserved.
104
9.
What is the value of Location in the output table?
a.
Italy
b.
France
c.
Belgium
d.
France Belgium Italy
data locALL;
merge loc1 loc2 loc3;
by Code;
run;
loc1
Code
Location
A
France
loc2
Code
Location
A
Belgium
loc3
Code
Location
A
Italy
1.2
Solutions
1-73
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
data locALL;
merge loc1 loc2 loc3;
by Code;
run;
Two DATA steps are needed. In the first DATA step,
dataset1
and
dataset2
can be merged by
Test.
In the second DATA step,
dataset3
can be merged with the result of the first DATA step by
Subject
.
Copyright © SAS Institute Inc. All rights reserved.
106
10.
A single DATA step can be used to merge the following three tables:
a.
True
b.
False
dataset1
Student
Test
Score
dataset2
Subject
Test
dataset3
Subject
AvgScore
1-74
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 6
The implied OUTPUT occurs after the DO loop. The value of
QTR
is 5, which is one increment
beyond the stop value of 4.
The index column is incremented at the bottom of each DO loop. The start and stop values must be
numeric when used with the keyword TO. The default increment is 1. The index column is in the final
table unless specifically dropped.
Copyright © SAS Institute Inc. All rights reserved.
109
1.
Which output table is produced from the following step?
a.
b.
c.
d.
data Earnings(keep=Qtr Earned);
Amount=1000; Rate=.075/4;
do Qtr=1 to 4;
Earned+(Amount+Earned)*Rate;
end;
run;
Copyright © SAS Institute Inc. All rights reserved.
111
2.
Which statement is true regarding the iterative DO loop?
a.
The start and stop values can be character or numeric values.
b.
If an increment value is not specified, the default increment is 0.
c.
The index column is incremented at the bottom of each DO loop.
d.
The index column is not in the final table unless specifically kept.
DO
index-column
=
start
TO
stop
<BY
increment
> ;
1.2
Solutions
1-75
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Four rows are in the output table, one row per each row in the input table. The implied OUTPUT is
after the nested DO loops.
The final value of
Year
is 2020, which is one increment beyond the stop value of 2019.
Copyright © SAS Institute Inc. All rights reserved.
113
3.
How many rows are in the output table given the following?
a.
1
b.
4
c.
5
d.
20
data work.savings;
set pg2.savings;
Savings=0;
do Year=1 to 5;
do qtr=1 to 4;
Savings+Amount;
Savings+(Savings*0.02/12);
end;
end;
run;
pg2.savings
Copyright © SAS Institute Inc. All rights reserved.
115
4.
What is the final value of Year given the following step?
a.
. (missing)
b.
2010
c.
2019
d.
2020
data invest;
do Year=2010 to 2019;
Capital+5000;
Capital+(Capital*.03);
end;
run;
1-76
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
When using WHILE or UNTIL in the DO statement, the expression must be in a set of parentheses.
For a, the index column is missing. For c, the parentheses are missing around the expression. For d,
the DATE values are character instead of numeric (‘01JAN2019’d).
For each row read in, three rows are created (one for each of three months). 2 rows read * 3 months
= 6 rows.
Copyright © SAS Institute Inc. All rights reserved.
117
5.
Which of the following statements contains valid syntax?
a.
do 1 to 10 by 2;
b.
do while (Year>2025);
c.
do until Earnings<=100000;
d.
do date='01JAN2019' to '31JAN2019';
Copyright © SAS Institute Inc. All rights reserved.
119
6.
How many rows are in the output table given the following?
a.
2
b.
3
c.
6
d.
12
e.
24
data bikeinfo2;
set bikeinfo;
do month=1 to 3;
do week=1 to 4;
bike=bike+2;
end;
output;
end;
run;
work.bikeinfo
1.2
Solutions
1-77
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
A DO UNTIL is evaluated at the bottom. The initial value of
X
is 15. The DO loop occurs one time
even though 15 is greater than 12 because the condition is not checked until the bottom of the loop.
15 becomes 16 before the condition is checked.
The DO UNTIL loop always executes at least one time because the condition is checked at the
bottom
of the loop. The DO WHILE loop executes only if the condition is true because the condition
is checked at the
top
of the loop.
Copyright © SAS Institute Inc. All rights reserved.
121
7.
What is the value of x at the completion of the DATA step?
a.
. (missing)
b.
13
c.
15
d.
16
data test;
x=15;
do until(x>12);
x+1;
end;
run;
Copyright © SAS Institute Inc. All rights reserved.
123
8.
Which statement is false?
a.
The DO UNTIL loop executes until a condition is true.
b.
The DO WHILE loop always executes at least one time.
c.
The DO WHILE loop checks the condition at the top of the loop.
d.
The DO UNTIL loop checks the condition at the bottom of the loop.
1-78
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
When combining an iterative with a conditional, you cannot use extra words such as AND, DO, or
OR. The conditional immediately follows the iterative.
On the second iteration of the DO loop,
DAY
=2 and
BIKE
=14. At the bottom of the loop,
DAY
becomes 3. At the top of the loop, the condition is checked. 14 exceeds 13, so the DO loop is over
with
DAY
=3 and
BIKE
=14.
Copyright © SAS Institute Inc. All rights reserved.
125
9.
Which of the following statements contains valid syntax?
a.
do Age=10 to 14 and while (Weight<150);
b.
do week=1 to 52 do until (Mileage ge 2750);
c.
do Increase=5 to 10 while (temperature lt 102);
d.
do Year=2018 to 2028 or until (Earnings<=100000);
Copyright © SAS Institute Inc. All rights reserved.
127
10.
Which output table is produced from the following step?
a.
b.
c.
d.
data test;
bike=10;
do day=1 to 7 while (bike lt 13);
bike=bike+2;
end;
run;
1.2
Solutions
1-79
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
Lesson 7
The measures (air travel) are spit into multiple columns, which is called a wide table.
data new;
set sashelp.air;
where year(date) between 1956 and 1958
and month(date) between 1 and 6;
Year=cats('Yr',year(date));
retain Jan Feb Mar Apr May Jun;
if month(date)=1 then Jan=Air;
else if month(date)=2 then Feb=Air;
else if month(date)=3 then Mar=Air;
else if month(date)=4 then Apr=Air;
else if month(date)=5 then May=Air;
else if month(date)=6 then Jun=Air;
if month(date)=6 then output;
keep Year Jan Feb Mar Apr May Jun;
run;
Copyright © SAS Institute Inc. All rights reserved.
130
1.
Which is the better description for the following table?
a.
wide table
b.
narrow table
1-80
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
When going from a wide table to a narrow table, the OUTPUT statement is needed to create multiple
rows from a single row during one iteration of the DATA step.
For each row read from the input table
work.airwide
, three rows are created (one for January data,
one for February data, and one for March data). Because there are three rows in the input table, the
final table
work.airnarrow
will contain 9 rows, (3 input rows * 3 rows created per each iteration).
Copyright © SAS Institute Inc. All rights reserved.
132
2.
Which statement is needed for creating multiple rows from a single row
when using the DATA step to go from a wide to a narrow table?
a.
WIDE
b.
NARROW
c.
RETAIN
d.
OUTPUT
Copyright © SAS Institute Inc. All rights reserved.
134
3.
How many rows will be in the final table if work.airwide contains three
rows?
a.
3
b.
6
c.
9
d.
12
data work.airnarrow;
set work.airwide;
Month='Jan';
Air=Jan;
output;
Month='Feb';
Air=Feb;
output;
Month='Mar';
Air=Mar;
output;
keep Year Month Air;
run;
1.2
Solutions
1-81
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
data airwide;
set sashelp.air;
where year(date) between 1956 and 1958
and month(date) between 1 and 6;
Year=cats('Yr',year(date));
retain Jan Feb Mar Apr May Jun;
if month(date)=1 then Jan=Air;
else if month(date)=2 then Feb=Air;
else if month(date)=3 then Mar=Air;
else if month(date)=4 then Apr=Air;
else if month(date)=5 then May=Air;
else if month(date)=6 then Jun=Air;
if month(date)=6 then output;
keep Year Jan Feb Mar Apr May Jun;
run;
data work.airnarrow;
set work.airwide;
Month='Jan’;
Air=Jan;
output;
Month='Feb';
Air=Feb;
output;
Month='Mar’;
Air=Mar;
output;
keep Year Month Air;
run;
1-82
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The RETAIN statement is needed when using the DATA step to go from a narrow table to a wide
table. The RETAIN statement holds values in the PDV across multiple iterations of the DATA step.
The KEEP statement controls the columns that makes it to the final table.
Due to the BY statement, the PDV contains a column named
First.Year
and a column named
Last.Year
.
Last.Year
will be equal to 1 when the last row of
Year
is read in from the input table. It is
during this iteration that the PDV contents need to be output.
Copyright © SAS Institute Inc. All rights reserved.
136
4.
When using the DATA step to go from a narrow table to a wide table, the
KEEP statement is needed to hold values in the PDV across multiple
iterations of the DATA step.
a.
True
b.
False
Copyright © SAS Institute Inc. All rights reserved.
138
5.
Which statement needs to be added to the DATA step to include only the
last row per Year in the output table?
a.
output;
b.
if Last then output;
c.
if Last.Year=1 then output;
d.
if Last.Year=0 then output;
data work.airwide2(keep=Year Jan Feb Mar);
set work.airnarrow;
by Year;
retain Jan Feb Mar;
if Month='Jan' then Jan=Air;
else if Month='Feb' then Feb=Air;
else if Month='Mar' then Mar=Air;
...
insert statement here
...
run;
1.2
Solutions
1-83
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
data airwide;
set sashelp.air;
where year(date) between 1956 and 1958
and month(date) between 1 and 6;
Year=cats('Yr',year(date));
retain Jan Feb Mar Apr May Jun;
if month(date)=1 then Jan=Air;
else if month(date)=2 then Feb=Air;
else if month(date)=3 then Mar=Air;
else if month(date)=4 then Apr=Air;
else if month(date)=5 then May=Air;
else if month(date)=6 then Jun=Air;
if month(date)=6 then output;
keep Year Jan Feb Mar Apr May Jun;
run;
data work.airnarrow;
set work.airwide;
Month='Jan';
Air=Jan;
output;
Month='Feb';
Air=Feb;
output;
Month='Mar';
Air=Mar;
output;
keep Year Month Air;
run;
data work.airwide2(keep=Year Jan Feb Mar);
set work.airnarrow;
by Year;
retain Jan Feb Mar;
if Month='Jan' then Jan=Air;
else if Month='Feb' then Feb=Air;
else if Month='Mar' then Mar=Air;
if Last.Year=1 then output;
run;
1-84
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
PROC TRANSPOSE cannot sort the data. The data needs to be sorted before the TRANSPOSE
statement. The BY statement transposes data within groups.
The BY statement transposes the data by the grouping of
Day
. The ID statement uses the values of
Meal
as the column headings. The VAR statement transposes the
Food
values into rows.
Copyright © SAS Institute Inc. All rights reserved.
140
6.
Which statement is false concerning the TRANSPOSE procedure?
a.
Columns are transposed into rows.
b.
By default, numeric columns are transposed.
c.
Use a BY statement to sort the data while transposing.
d.
Use a VAR statement to specifically specify the character and numeric
columns to transpose.
Copyright © SAS Institute Inc. All rights reserved.
142
7.
Which statements are needed in a PROC TRANSPOSE step for the
following example (narrow
wide)?
a.
b.
c.
d.
by Day;
id Food;
var Meal;
by Day;
var Meal Food;
id Day;
var Food Meal;
by Day;
id Meal;
var Food;
1.2
Solutions
1-85
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
data meals;
length Day Meal Food $ 10;
input Day $ Meal $ Food $;
datalines;
Saturday Breakfast Yogurt
Saturday Lunch Sandwich
Saturday Dinner Steak
Sunday Breakfast Pancakes
Sunday Lunch Salad
Sunday Dinner Lasagna
;
run;
proc transpose data=meals out=meals1(drop=_name_);
by Day;
id Meal;
var Food;
run;
1-86
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The columns of
Breakfast,
Lunch
, and
Dinner
are transposed into rows.
data meals;
length Day Meal Food $ 10;
input Day $ Meal $ Food $;
datalines;
Saturday Breakfast Yogurt
Saturday Lunch Sandwich
Saturday Dinner Steak
Sunday Breakfast Pancakes
Sunday Lunch Salad
Sunday Dinner Lasagna
;
run;
proc transpose data=meals out=meals1(drop=_name_);
by Day;
id Meal;
var Food;
run;
proc transpose data=meals1 out=meals2;
var Breakfast Lunch Dinner;
run;
Copyright © SAS Institute Inc. All rights reserved.
144
8.
Which statement or statements are needed in a PROC TRANSPOSE step
for the following example (wide
narrow)?
a.
b.
c.
d.
id Day;
by Day;
var Breakfast Lunch Dinner;
id Day;
var Breakfast Lunch Dinner;
1.2
Solutions
1-87
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The NAME= option specifies the name for the column in the output table that contains the name of
the column that is being transposed to create the current row. The default name is
_NAME_
.
data meals;
length Day Meal Food $ 10;
input Day $ Meal $ Food $;
datalines;
Saturday Breakfast Yogurt
Saturday Lunch Sandwich
Saturday Dinner Steak
Sunday Breakfast Pancakes
Sunday Lunch Salad
Sunday Dinner Lasagna
;
run;
proc transpose data=meals out=meals1(drop=_name_);
by Day;
id Meal;
var Food;
run;
proc transpose data=meals1 out=meals2 name=Meal;
var Breakfast Lunch Dinner;
run;
Copyright © SAS Institute Inc. All rights reserved.
146
9.
Which option is needed in the PROC TRANSPOSE statement to rename
the _NAME_ column?
a.
_name_=Meal
b.
name=Meal
c.
prefix=Meal
d.
rename=Meal
1-88
Lesson 1
Lesson Quizzes
Copyright © 2022, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED.
The RENAME= data set option can be used to change the names of the COL columns.
data meals;
length Day Meal Food $ 10;
input Day $ Meal $ Food $;
datalines;
Saturday Breakfast Yogurt
Saturday Lunch Sandwich
Saturday Dinner Steak
Sunday Breakfast Pancakes
Sunday Lunch Salad
Sunday Dinner Lasagna
;
run;
proc transpose data=meals out=meals1(drop=_name_);
by Day;
id Meal;
var Food;
run;
proc transpose data=meals1
out=meals2(rename=(COL1=Day_7 COL2=Day_1))
name=Meal;
var Breakfast Lunch Dinner;
run;
Copyright © SAS Institute Inc. All rights reserved.
148
10.
Which option is needed in the PROC TRANSPOSE statement to rename
the COL columns?
a.
out=meals2(COL1=Day_7 COL2=Day_1)
b.
out=meals2(name=(COL1=Day_7 COL2=Day_1))
c.
out=meals2(rename=(COL1=Day_7 COL2=Day_1))
d.
out=meals2(prefix=(COL1=Day_7 COL2=Day_1))