SAS (Spring 12) HW#2 2/13/2012 NAME: Due on 2/20/2012 1. How

advertisement
SAS (Spring 12)
HW#2
2/13/2012
NAME: _____________________________________________________________
Due on 2/20/2012
1. How many program steps are executed when the program below is processed? ANS: __________
data user.tables;
infile jobs;
input date name $ job $;
run;
proc sort data=user.tables;
by name;
run;
proc print data=user.tables;
run;
2. What type of variable is the variable Wear in the data set below?
Brand
Acme
Ajax
Atlas
Wear
43
34
ANS: __________________
Cost
67.0
80.0
45.
3 . Which of the following files is a permanent SAS file? ANS: _______________________
a. Sashelp.PrdSale
b. Sasuser.MySales
c. Profits.Quarter1
d. work.sales
4. In a DATA step, how can you reference a temporary SAS data set named Forecast? ANS: ________
a. Forecast
b. work.Forecast
c. Sales.Forecast (after assigning the libref Sales)
d. only a and b above
5. How many statements does the following SAS program contain?
ANS: __________________
proc print data=new.prodsale
label double;
var state day price1 price2; where state='NC';
label state='Name of State';
title ‘Product Sales’;
run;
Use the following program to answer the True /False questions 6 to 10:
options pagesize=55 nonumber;
proc print data=s12.admit noobs;
id actlevel;
var actlevel age height weight;
sum fee;
run;
options pageno=1 linesize=80 obs=20;
proc print data=s12.heart (firstobs=5 obs= 10);
var arterial heart cardiac urinary;
run;
proc print data = s12.insure; run;
options firstobs = 10 obs=15;
data heart1; set s12.heart;
proc print data=heart1 (firstobs=4 obs=max);
var id sex heart cardiac;
id id;
run;
6. The output of the Admit data set has the date shown, but no page number.
ANS: ______________
7. The output of heart consists of case 5 to case 10, but no page number.
ANS: ______________
8. The output for the Insure data consists of all cases in the insure data set.
ANS: ________________
9. The output of Admit data has the following variables from left to right:
Actlevel age height weight
ANS: ______________
10. The output from the last PROC PRINT statement results in 6 observations. ANS: ____________
11. Suppose you use the option yearcutoff = 1960. Determine the dates SAS interprets:
Date expression (month/day/year)
8/15/35
8/15/60
8/15/75
8/15/05
Interpreted date(m/d/y)
12. Which of the following programs correctly references a SAS data set named SalesAnalysis that is stored in a
permanent SAS library? ANS: _______________
data saleslibrary.salesanalysis;
set mydata.quarter1sales;
run;
b. data mysales.totals;
set sales_99.salesanalysis;
run;
c. proc print data=salesanalysis.quarter1;
var sales salesrep month;
run;
d. proc print data=1999data.salesanalysis;
run;
a.
13. What usually happens when an error is detected?
ANS: _______________________
a. SAS continues processing the step.
b. SAS continues to process the step, and the log displays messages about the error.
c. SAS stops processing the step in which the error occurred, and the log displays messages about the
error.
d. SAS stops processing the step in which the error occurred, and the program output displays messages
about the error.
14. A syntax error occurs when
ANS: _________________________
a. some data values are not appropriate for the SAS statements that are specified in a program.
b. the form of the elements in a SAS statement is correct, but the elements are not valid for that usage.
c. program statements do not conform to the rules of the SAS language.
d. none of the above.
15. What does the following log indicate about your program?
ANS: ________________
proc print data=sasuser.cargo99
var origin dest cargorev;
22
76
ERROR 22-322: Syntax error, expecting one of the
following:
;, (, DATA, DOUBLE, HEADING, LABEL,
N, NOOBS, OBS, ROUND, ROWS, SPLIT, STYLE,
UNIFORM, WIDTH.
ERROR 76-322: Syntax error, statement will be ignored.
11
run;
a. SAS identifies a syntax error at the position of the VAR statement.
b. SAS is reading VAR as an option in the PROC PRINT statement.
c. SAS has stopped processing the program because of errors.
d. all of the above
16. Which PROC PRINT step creates the following output? ANS: _________________
Date
On Changed Flight
232
18
219
04MAR99
160
4
219
05MAR99
163
14
219
06MAR99
241
9
219
07MAR99
183
11
219
08MAR99
211
18
219
09MAR99
167
7
219
10MAR99
a. proc print data=flights.laguardia;
var date on changed flight;
where changed>3; run;
b. proc print data=flights.laguardia noobs;
var on changed flight;
where on>=160; run;
c. proc print flights.laguardia noobs;
id date;
var date on changed flight;
where flight='219'; run;
d. proc print data=flights.laguardia;
id date;
var on changed flight;
where flight='219'; run;
e. None of the above.
17. Which of the following statements selects from a data set only those observations for which the value of the
variable Style is RANCH, SPLIT, or TWOSTORY?
ANS: _____________
a. where
b. where
c. where
d. where
style='RANCH' or 'SPLIT' or 'TWOSTORY';
style in ('RANCH','SPLIT','TWOSTORY');
style in 'RANCH' or 'SPLIT' or 'TWOSTORY';
style in (RANCH, SPLIT, TWOSTORY);
18. If you want to sort your data and create a temporary data set named Calc to store the sorted data, which of
the following steps should you submit?
ANS: ________________
a.
b.
c.
d.
proc
proc
proc
proc
sort
sort
sort
sort
data=calc out=finance.dividend; run;
dividend out=calc; by account; run;
data=finance.dividend out= calc; by account; run;
from finance.dividend to calc; by account; run;
19. Which options are used to create the following PROC PRINT output? ANS: _______________
13:27 Monday, September 2, 2009
Patient
203
54
664
210
101
Arterial
88
83
72
74
80
Heart
95
183
111
97
130
Cardiac
66
95
332
369
291
Urinary
110
0
12
0
0
a. the DATE system option and the LABEL option in PROC PRINT
b. the DATE and PAGENO=3 system options and NOOBS options in PROC PRINT
c. the DATE and NONUMBER system options and the DOUBLE option in PROC PRINT
d. the DATE system options
20. What happens if you submit the following program?
ANS: ____________________
proc sort data=clinic.diabetes; by descending age; run;
proc print data=clinic.diabetes;
var age height weight pulse;
where sex='F';
run;
a. The PROC PRINT step runs successfully, printing observations in their sorted order.
b. The PROC SORT step generates errors and stops processing, but the PROC PRINT step runs successfully,
printing observations in their original (unsorted) order.
c. The PROC SORT step runs successfully, but the PROC PRINT step generates errors and stops processing.
d. None of the above.
21. Choose the statement below that selects rows in which
 the amount is less than or equal to $5000
 the account is 101–1000, or the rate greater than 0.095.
a.
ANS: _____________
where amount <= 5000 or account='101-1000' and rate >= 0.095;
b. where amount <= 5000 and account='101-1000' or rate ge 0.095;
c.
where (amount le 5000 and account='101-1000') or rate > 0.095;
d. where amount <= 5000 and (account='101-1000' or rate gt 0.095);
3
Part 2: Write a SAS program to do the following tasks:
(1) Create a library HW2 that connects to the folder HWDATA in your C-drive.
[Note: you need to create HWDATA folder in your C-drive prior to create the HW2 library in your
program.]
(2) Set the system options to have the output starting at page #1.
(3) Read the SAS data set Insure in the SASData folder inside sas_s12 folder in your C-drive to a SAS
library HW2, and call the data set Insure_hw2. Then, create permanent variable labels for the variables:
Pcinsured : Percent/Insured
Total
: Total/Balance
[NOTE: In your PROC PRINT statement, make sure you use SPLIT = ‘/’ option. ]
(4) Sort the data by the variable ID using PROC SORT, and use OUT= to save the sorted data in the HW2
library using the data set name: Insure_s.
(5) Use PROC PRINT to produce the following report based on the data set Insure_s:
(i) Use the variable ID as the id variable.
(ii) Print variables Name, Policy, Pctinsured, Total
(iii) Select individuals whose ID having the 2nd digit from left is ‘5’.
(iv) Select only Total > 300.
(v) Add the Title statement ‘Individuals whose total premium over $300’.
(vi) Make sure you have the Variable Labels for Pcincured and Total.
The Insure data consists of the following variables:
Variable
Type Length Description
ID
Char
8
Name
char
20
Policy
Char
5
Company
char
11
client ID number
client name
client policy number
name of company
PctInsured num
3
percent insured
Total
num
8
total balance
BalanceDue num
8
balance due
A sample data is give below:
ID
Name
Policy Company
2458 Murray, W
32668 MUTUALITY
2462 Almers, C
95824 RELIABLE
2501 Bonaventure, T 87795 A&R
NOTE: Add your results of the program here by including
(1) Your correct program
(2) The SAS Log
(3) The output
PctInsured Total BalanceDue
100
98.64
0.00
80 780.23
156.05
80
47.38
9.48
Download