Sas Questions
Sas Questions
1. Identify which of the following variable names are valid SAS names:
Height
HeightInCentimeters
Height_in_centimeters
Wt-Kg
x123y456
76Trombones
MiXeDCasE
2. In the following list, classify each data set name as valid or invalid:
Clinic
clinic
work
hyphens-in-the-name
123GO
Demographics_2006
3. You have a data set consisting of Student ID, English, History, Math, and Science
test scores on 10 students.
a. The number of variables is __________
b. The number of observations is __________
4. True or false:
a. You can place more than one SAS statement on a single line.
b. You can use several lines for a single SAS statement.
c. SAS has three data types: character, numeric, and integer.
d. OPTIONS and TITLE statements are considered global statements.
5. What is the default storage length for SAS numeric variables (in bytes)?
6. You have a text file called stocks.txt containing a stock symbol, a price, and the
number of shares. Here are some sample lines of data:
File stocks.txt
AMGN 67.66 100
DELL 24.60 200
GE 34.50 100
HPQ 32.32 120
IBM 82.25 50
MOT 30.24 100
a. Using this raw data file, create a temporary SAS data set (Portfolio). Choose
your own variable names for the stock symbol, price, and number of shares. In
addition, create a new variable (call it Value) equal to the stock price times the
number of shares. Include a comment in your program describing the purpose of
the program, your name, and the date the program was written.
b. Write the appropriate statements to compute the average price and the average
number of shares of your stocks.
7. Given the program here, add the necessary statements to compute four new variables:
a. Weight in kilograms (1 kg = 2.2 pounds). Name this variable WtKg.
b. Height in centimeters (1 inch = 2.54 cm). Name this variable HtCm.
c. Average blood pressure (call it AveBP) equal to the diastolic blood pressure plus
one-third the difference of the systolic blood pressure minus the diastolic blood
pressure.
d. A variable (call it HtPolynomial) equal to 2 times the height squared plus 1.5
times the height cubed.
10. Run the program here to create a permanent SAS data set called Perm. You will
need to modify the program to specify a folder where you want to place this data set.
Run PROC CONTENTS on this data set and then use the SAS Explorer to
investigate the properties of this data set as well.
libname learn 'c:\your-folder-name';
data learn.perm;
input ID : $3. Gender : $1. DOB : mmddyy10.
Height Weight;
label DOB = 'Date of Birth'
Height = 'Height in inches'
Weight = 'Weight in pounds';
format DOB date9.;
datalines;
001 M 10/21/1946 68 150
002 F 5/26/1950 63 122
003 M 5/11/1981 72 175
004 M 7/4/1983 70 128
005 F 12/25/2005 30 40
;
11. Run PROC PRINT on the data set you created in Problem 1. Use the SAS
VIEWTABLE window to open this data set and compare the headings in the
window to the column headings from your PROC PRINT. What is the difference?
12. Run this program to create a permanent SAS data set called Survey2007. Close your SAS
session, open up a new session, and write the statements necessary to compute the mean age.
* Write your LIBNAME statement here;
data –fill in your data set name here- ;
input Age Gender $ (Ques1-Ques5)($1.);
/* See Chapter 21, Section 14 for a discussion
of variable lists and format lists used above */
datalines;
23 M 15243
30 F 11123
42 M 23555
48 F 55541
55 F 42232
62 F 33333
68 M 44122
;
* Write your libname statement here;
proc means data= - insert the correct data set name -;
var Age;
run;