0% found this document useful (0 votes)
1K views

Sas Questions

1. The valid SAS variable names from the list provided are: Height, HeightInCentimeters, MiXeDCasE, x123y456. The names Height_in_centimeters and Wt-Kg contain invalid characters, and 76Trombones is not a valid name as it begins with a number. 2. The valid data set names from the list provided are: Clinic, work, Demographics_2006. The names clinic and hyphens-in-the-name contain invalid characters, and 123GO is not valid as it begins with a number. 3. For the student data set described, the number of variables is 5 (Student ID, English, History, Math,

Uploaded by

gaggy1983
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Sas Questions

1. The valid SAS variable names from the list provided are: Height, HeightInCentimeters, MiXeDCasE, x123y456. The names Height_in_centimeters and Wt-Kg contain invalid characters, and 76Trombones is not a valid name as it begins with a number. 2. The valid data set names from the list provided are: Clinic, work, Demographics_2006. The names clinic and hyphens-in-the-name contain invalid characters, and 123GO is not valid as it begins with a number. 3. For the student data set described, the number of variables is 5 (Student ID, English, History, Math,

Uploaded by

gaggy1983
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

Here is the program for you to modify:


data prob2;
input ID $
Height /* in inches */
Weight /* in pounds */
SBP /* systolic BP */
DBP /* diastolic BP */;
< place your statements here >
datalines;
001 68 150 110 70
002 73 240 150 90
003 62 101 120 80
;
title "Listing of PROB2";
proc print data=prob2;
run;
Note: This program uses a DATALINES statement, which enables you to include the
input data directly in the program. You can read more about this statement in
the next chapter.

8. You are given an equation to predict electromagnetic field (EMF) strength, as


follows:
EMF = 1.45 x V + (R/E) x V3 – 125.
If your SAS data set contains variables called V, R, and E, write a SAS assignment
statement to compute the EMF strength.

9. What is wrong with this program?


001 data new-data;
002 infile prob4data.txt;
003 input x1 x2
004 y1 = 3(x1) + 2(x2);
005 y2 = x1 / x2;
006 new_variable_from_x1_and_x2 = x1 + x2 – 37;
007 run;
Note: Line numbers are for reference only; they are not part of the program.

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;

You might also like