You are on page 1of 5

Sample Question

The United States Bureau of Labor Statistics publishes various indexes that
measure average prices of consumer goods in urban areas. The SAS data set
AVEPRICES contains data on the average price of unleaded regular gasoline (per
gallon), whole large eggs (per dozen), and whole milk (per gallon) for a 10-year
period by month in the United States. The variables in this file are year, month,
price, and type of commodity.

a. Examine this SAS data set including the variable labels and attributes. Use
one or more procedures to create a data set that contains the average price per
year for each commodity.
b. Using one or more procedures, create a new version of this data set that has 12
variables corresponding to each month, that contain the price data for each
combination of commodity and year.
c. Combine the averages calculated in part a) with the data set created in part b).
d. In one DATA step, divide the data set from part c) into three data sets that
correspond to the three commodities.
e. Add code to the DATA step in part d) that will give the variables for months
better names. The final data sets should not include any automatic variables
that may have been created along the way.
Answer
a)
The data set is read into SAS as table ‘avgprices’. A new table ‘avgprices1’ is created using PROC SQL
which has the average price of each commodity per year. Table is shown as below

Avgprices table:

Avgprices1 table:
b)
Created a new SAS table ‘avgpricesnew’ using the PROC TRANSPOSE that has 12 variables for each
month with records for every combination and commodity. The screen shot of this table is provided
below.

c)
A new table ‘avgpricescombined’ has been created by combining datasets from (a) and (b) using MERGE
operation Merge operation. Both, average price per year for each commodity and monthly price are
visible in the below screenshot
d)
From the table ‘avgpricescombined’ three different tables have been created for each commodity Egg,
Gas and Milk.

e)
The names of the month variables have been changed while creating three commodity tables Egg, Gas
and Milk. The screenshots of the 3 tables are shown below

Egg
Gas

Milk

You might also like